Parse Functions‎ > ‎

Sheet1 to WBs

"I have a master sheet with all data on it. I need to parse this data out to individual WORKBOOKS based on the values in a single column.  The workbooks should be named for the values in that column plus today's date."

  1. Titles are in row 1 and will be duplicated in all workbooks
  2. Column to evaluate from should be easily adjustable, sometimes we parse by column A, other times by column B, etc.
  3. Workbooks are named for the value used to create each workbook, plus the current date
  4. Macro should provide some sort of double check at the end
  5. NOTE:  The SaveAs command in the macro is different for Excel 2000-2003 and for 2007+, choose the correct one to use
This macro will accomplish this. Only the first 3 lines need editing for the ws name, SvPath string, and vTitles range.


Option Explicit

Sub ParseItems()
'Jerry Beaucaire  (4/22/2010)
'Based on selected column, data is filtered to individual workbooks
'workbooks are named for the value plus today's date
Dim LR As Long, Itm As Long, MyCount As Long, vCol As Long
Dim ws As Worksheet, MyArr As Variant, vTitles As String, SvPath As String

'Sheet with data in it
   Set ws = Sheets("Original Data")

'Path to save files into, remember the final \
    SvPath = "C:\2010\"

'Range where titles are across top of data, as string, data MUST

'have titles in this row, edit to suit your titles locale
    vTitles = "A1:Z1"
'Choose column to evaluate from, column A = 1, B = 2, etc.
   vCol = Application.InputBox("What column to split data by? " & vbLf _
        & vbLf & "(A=1, B=2, C=3, etc)", "Which column?", 1, Type:=1)
   If vCol = 0 Then Exit Sub

'Spot bottom row of data
   LR = ws.Cells(ws.Rows.Count, vCol).End(xlUp).Row

'Speed up macro execution
   Application.ScreenUpdating = False

'Get a temporary list of unique values from key column 
    ws.Columns(vCol).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ws.Range("EE1"), Unique:=True

'Sort the temporary list
    ws.Columns("EE:EE").Sort Key1:=ws.Range("EE2"), Order1:=xlAscending, Header:=xlYes, _
       OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

'Put list into an array for looping (values cannot be the result of formulas, must be constants)
    MyArr = Application.WorksheetFunction.Transpose(ws.Range("EE2:EE" & Rows.Count).SpecialCells(xlCellTypeConstants))

'clear temporary worksheet list

'Turn on the autofilter, one column only is all that is needed

'Loop through list one value at a time
    For Itm = 1 To UBound(MyArr)
        ws.Range(vTitles).AutoFilter Field:=vCol, Criteria1:=MyArr(Itm)
        ws.Range("A1:A" & LR).EntireRow.Copy
        Range("A1").PasteSpecial xlPasteAll
        MyCount = MyCount + Range("A" & Rows.Count).End(xlUp).Row - 1
        ActiveWorkbook.SaveAs SvPath & MyArr(Itm) & Format(Date, " MM-DD-YY"), xlNormal
        'ActiveWorkbook.SaveAs SvPath & MyArr(Itm) & Format(Date, " MM-DD-YY") & ".xlsx", 51   'use for Excel 2007+
        ActiveWorkbook.Close False
        ws.Range(vTitles).AutoFilter Field:=vCol
    Next Itm

    ws.AutoFilterMode = False
    MsgBox "Rows with data: " & (LR - 1) & vbLf & "Rows copied to other sheets: " & MyCount & vbLf & "Hope they match!!"
    Application.ScreenUpdating = True
End Sub

Nothing says "thanks" like a steak dinner!
PayPal - The safer, easier way to pay online!