VBA solution to create worksheets based on cell value and then copy data to its new worksheet

sachavez

Active Member
Joined
May 22, 2009
Messages
469
Hello,

I'm looking for some code that will:

1. Evaluate my data set in my "test" worksheet. The header for my data set begins in worksheet("Test"), cell A3, and the size of the data set varies weekly.
2. Create new worksheets (and name the new worksheet) based on the cell content is the "Test" worksheet, to newly created worksheets, range("J4") to the end of column J.
3. Copy the data from my test worksheet to the newly created worksheets.

Thanks in advance.

Steve
 
The shipper column is column J.

You can see that there are two transactions for shipper (OR CUSTOMER) ADVANCSTEREC, so I would want all of their transactions in the same work sheet. The rows end in column Q (I left off a few columns, below)


InitNumberStationSTTrack/
Sequence
Train IDDivisionOrigin
Station
Or
ST
ShipperDestination
Station
Ds
ST
Consignee
ADMX15599BARSTOWCA1508- 34 CALIFORNIAMARSHALLMNADMCORPROCESCOLTONCAARCHERDANMID
BNSF518052KAISERCA2126- 1 CALIFORNIAFONTANACAADVANCSTERECARMORELARNUCORYSTEEL
MWCX204154KAISERCA2126- 2 CALIFORNIAFONTANACAADVANCSTERECBEAUMONTTXOPTIMUSTELLC
GRW4391PITTSBURGCA0699-107 CALIFORNIASTLOUISMOAGENTMADISONILDELIVESWITCH
GACX55610SPRINGFIEMO0111- 18 HEARTLANDKANCITYKSAGPROINCACOOMONETTMOTYSONFOODS
TILX54864AMASYARDTX0104- 11 KANSASDAWSONMNAGPROINCACOODALHARTTXCARGILL
TILX55193AMASYARDTX0104- 12 KANSASDAWSONMNAGPROINCACOODALHARTTXCARGILL

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Considering the following:
- Name Sheet: "test".
- headings: row 3.
- start of data row 4.
- Important: customer sheets do not exist.

Try:

Code:
Sub create_worksheets()
  Dim c As Range, sh As Worksheet, ky As Variant
  Set sh = Sheets("test")
  With CreateObject("scripting.dictionary")
     For Each c In sh.Range("J4", sh.Range("J" & Rows.Count).End(xlUp))
        If c.Value <> "" Then .Item(c.Value) = Empty
     Next c
     For Each ky In .Keys
        sh.Range("A3").AutoFilter Columns("J").Column, ky
        Sheets.Add(, Sheets(Sheets.Count)).Name = ky
        sh.AutoFilter.Range.EntireRow.Copy Range("A3")
     Next ky
  End With
  sh.Select
  sh.ShowAllData
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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