Split workbook with multiple worksheets by first column entries, into multiple workbooks with same sheets (per entry)

vtidus

New Member
Joined
Dec 14, 2017
Messages
4
Good evening to all,

It is very nice to meet you! I would like your help for a vba code to do the following:

I have a workbook containing sheets A, B, C. All sheets have the column "Name" as their first column (there might be multiple lines with the same name).
I would like to split the files per unique name into multiple workbooks all containing the same sheets. I.e. one file would include only John's relevant rows in sheets A, B, C, the next file would only include Mary's etc. until there are individual workbooks for each of the entries of column "Name".

Could you please guide me a little bit or ideally provide a code for this?

Thank you very much!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi & welcome to the board
As you haven't given us much info, I've made some assumptions
You have only 3 sheets in your original workbook
You have a header row in row 1
your data starts in A2
All files will be xlsm format & saved in the same folder as the original.
The original workbook will be the active workbook when you run this code
Code:
Sub SplitData()

   Dim Cl As Range
   Dim Ky As Variant
   Dim UsdRws As Long
   Dim Wbk As Workbook
   Dim SrcWbk As Workbook
   Dim Ws As Worksheet
   
   Set SrcWbk = ActiveWorkbook
Application.ScreenUpdating = False

   With CreateObject("scripting.dictionary")
      For Each Ws In SrcWbk.Worksheets
         For Each Cl In Ws.Range("A2", Ws.Range("A" & Rows.Count).End(xlUp))
            If Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
         Next Cl
      Next Ws
      For Each Ky In .keys
         Set Wbk = Workbooks.Add
         Wbk.Sheets.Add after:=Sheets(1)
         Wbk.Sheets.Add after:=Sheets(2)
         For Each Ws In SrcWbk.Worksheets
            If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
            Ws.Range("A1").AutoFilter 1, Ky
            Ws.UsedRange.SpecialCells(xlVisible).Copy Wbk.Sheets(Ws.Index).Range("A1")
         Next Ws
         Wbk.SaveAs SrcWbk.Path & "\" & Ky & ".xlsm", 52
         Wbk.Close
      Next Ky
   End With
   For Each Ws In SrcWbk.Worksheets
      Ws.AutoFilterMode = False
   Next Ws
      
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,171
Messages
6,129,281
Members
449,498
Latest member
Lee_ray

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