Need help with writting a macro

Trowo

New Member
Joined
Dec 15, 2014
Messages
22
I am trying to automate a feed that I download into sheet 1 (master) each morning. The feed has none-sense in the first 12 rows but it always comes in that way. Column D has a list of letters that I want to filter by and assign to their own worksheets. I cannot copy the entire row; but rather I want column A to be the same on the separate sheets, column C on master to be column B on indiv. sheets and columns E & F to be columns D & E respectively on the individual sheets. Column B is of no use to me but comes in on the feed and column D is only used in the master sheet for the filter. So the indiv. sheets would have the first four columns populated with data from the master sheet.

Thanks in advance-

ABCDEF
ATVIActivision Blizzard IncA100$100.00
AIROAirspan Networks Inc.A200$400.00
AMZNAmazon.com, Inc.A300$900.00
AMBRAmber Road, Inc.A200$800.00
AMCXAMC Networks Inc. Class AA100$500.00
AMTAmerican Tower CorporationA200$1,200.00
ANSSANSYS, Inc.A300$2,100.00
AZPNAspen Technology, Inc.A257$2,057.14
ADSKAutodesk, Inc.A271$2,442.86
AVIDAvid Technology, Inc.A286$2,857.14
BTNBallantyne Strong, Inc.A300$3,300.00
BBGIBeasley Broadcast Group, Inc. Class AA314$3,771.43
BSQRBSQUARE CorporationA329$4,271.43
CVCCablevision Systems Corporation Class AA343$4,800.00
CDNSCadence Design Systems, Inc.A357$5,357.14
ATMLAtmel CorporationB371$5,942.86
AVXAVX CorporationB386$6,557.14
BELFBBel Fuse Inc. Class BB400$7,200.00
BHEBenchmark Electronics, Inc.B414$7,871.43
BWABorgWarner Inc.B429$8,571.43
CAVMCavium, Inc.B443$9,300.00
CKPCheckpoint Systems, Inc.B457$10,057.14
CIENCiena CorporationB471$10,842.86
CRUSCirrus Logic, Inc.B486$11,657.14
CSCOCisco Systems, Inc.B500$12,500.00
GLWCorning IncorporatedB100$100.00
CRAYCray Inc.B200$400.00
DGIIDigi International Inc.B300$900.00
EMANeMagin CorporationB200$800.00
EXCExelon CorporationC100$500.00
XOMExxon Mobil CorporationC200$1,200.00
FEFirstEnergy Corp.C300$2,100.00
FTIFMC Technologies, Inc.C257$2,057.14
FSTForest Oil CorporationC271$2,442.86
GXPGreat Plains Energy IncorporatedC286$2,857.14
HALHalliburton CompanyC300$3,300.00
HEHawaiian Electric Industries, Inc.C314$3,771.43
HLXHelix Energy Solutions Group, Inc.C329$4,271.43
NMRXNumerex Corp. Class AGM343$4,800.00
VZVerizon Communications Inc.GM357$5,357.14
APPAmerican Apparel, Inc.J371$5,942.86
AATAmerican Assets Trust, Inc.J386$6,557.14
ACCAmerican Campus Communities, Inc.J400$7,200.00
MTGEAmerican Capital Mortgage Investment Corp.J414$7,871.43
AEOAmerican Eagle Outfitters, Inc.J429$8,571.43
AIVApartment Investment and Management Company Class AJ443$9,300.00
ABRArbor Realty Trust, Inc.J457$10,057.14
ACREAres Commercial Real Estate CorporationJ471$10,842.86
AHPAshford Hospitality Prime, Inc.J486$11,657.14
AHTAshford Hospitality Trust, Inc.J500$12,500.00
MMCMarsh & McLennan Companies, Inc.L100$100.00
MBWMMercantile Bank CorporationL200$400.00
METMetLife, Inc.L300$900.00
MSMorgan StanleyL200$800.00
NYCBNew York Community Bancorp, Inc.L100$500.00
NTRSNorthern Trust CorporationL200$1,200.00
NSAMNorthStar Asset Management CorpL300$2,100.00
PKBKParke Bancorp, Inc.L257$2,057.14
PNCPNC Financial Services Group, Inc.L271$2,442.86
GISGeneral Mills, Inc.M286$2,857.14
THRMGentherm IncorporatedM300$3,300.00
SJMJ. M. Smucker CompanyM314$3,771.43
KARKAR Auction Services, Inc.M329$4,271.43
KKellogg CompanyM343$4,800.00
KMBKimberly-Clark CorporationM357$5,357.14
KRFTKraft Foods Group, Inc.M371$5,942.86
KRKroger Co.M386$6,557.14
LMNRLimoneira CompanyM400$7,200.00
CAHCardinal Health, Inc.P414$7,871.43
CFNCareFusion CorporationP429$8,571.43
CELGCelgene CorporationP443$9,300.00
CLDXCelldex Therapeutics, Inc.P457$10,057.14
CERNCerner CorporationP471$10,842.86
CRLCharles River Laboratories International, Inc.P486$11,657.14
CICigna CorporationP500$12,500.00
ETNEaton Corp. PlcS100$100.00
ECLEcolab Inc.S200$400.00
ESVEnsco plcS300$900.00
FSSFederal Signal CorporationS200$800.00
FLRFluor CorporationS100$500.00
FMCFMC CorporationS200$1,200.00

<colgroup><col span="2"><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
So the indiv. sheets would have the first four columns populated with data from the master sheet.
I think you meant that columhns E and F from the Master would become C and D on the individual sheets.

Code:
Sub NewSheets()
Dim sh As Worksheet, lr As Long, c As Range, ns As Worksheet
Set sh = Sheets("master") 'Edit sheet name
lr = sh.Cells(Rows.Count, 4).End(xlUp).Row
sh.Range("D1:D" & lr).AdvancedFilter xlFilterCopy, , sh.Range("H1"), True
    For Each c In sh.Range("H1", sh.Cells(Rows.Count, "H").End(xlUp))
        sh.Range("D1:D" & lr).AutoFilter 1, c.Value
        Set ns = Sheets.Add
        sh.Range("D2:D" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Copy ns.Range("A2")
        Range("B1, D1").EntireColumn.Delete
        sh.Range("D:D").AutoFilter
    Next
End Sub
 
Upvote 0
I think you meant that columhns E and F from the Master would become C and D on the individual sheets.

Code:
Sub NewSheets()
Dim sh As Worksheet, lr As Long, c As Range, ns As Worksheet
Set sh = Sheets("master") 'Edit sheet name
lr = sh.Cells(Rows.Count, 4).End(xlUp).Row
sh.Range("D1:D" & lr).AdvancedFilter xlFilterCopy, , sh.Range("H1"), True
    For Each c In sh.Range("H1", sh.Cells(Rows.Count, "H").End(xlUp))
        sh.Range("D1:D" & lr).AutoFilter 1, c.Value
        Set ns = Sheets.Add
        sh.Range("D2:D" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Copy ns.Range("A2")
        Range("B1, D1").EntireColumn.Delete
        sh.Range("D:D").AutoFilter
    Next
End Sub

That did not seem to work... not sure if it had something to do with the text or links in the first 12 rows... is it possible to see where I can manipulate the code to match my needs?
 
Upvote 0
See if this does any better. It will work with data beginning in row 13.
Code:
Sub NewSheets()
Dim sh As Worksheet, lr As Long, c As Range, ns As Worksheet
Set sh = Sheets("master") 'Edit sheet name
lr = sh.Cells(Rows.Count, 4).End(xlUp).Row
sh.Range("D12:D" & lr).AdvancedFilter xlFilterCopy, , sh.Range("H1"), True
    For Each c In sh.Range("H2", sh.Cells(Rows.Count, "H").End(xlUp))
        sh.Range("D12:D" & lr).AutoFilter 1, c.Value
        Set ns = Sheets.Add(After:=Sheets(Sheets.Count))
        sh.Range("D13:D" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Copy ns.Range("A2")
        Range("B1, D1").EntireColumn.Delete
        sh.Range("D:D").AutoFilter
    Next
sh.Columns("H").ClearContents
End Sub
This has been tested in a mock up an ran without error producing expected results. The code should be copied to the standard code module 1. See below for accessing code module.
What the code does: It first filters unique codes out of column D and puts that list in column H temporarily. It then uses column H list to sytematically filter all items with a particular code and place that filtered list, entire rows, into a new worksheet. When each item on the list in column H has been filtered and copied, it will clear column H and end the procedure. If the procedure does not complete and an error message is produced, click the 'Debug' button on the dialog box and note the highlighted line of code, then post that information back to this thread.

Also, be sure to check that the sheet name in the code is the same as the actual sheet name.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,721
Messages
6,126,447
Members
449,314
Latest member
MrSabo83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top