Split 1 Workbook With Worksheet Tab For Each Dept Into Individual Workbooks

Bob R

New Member
Joined
Nov 20, 2019
Messages
4
SUMMARY:
Is there a method (simple?) to copy the 30-40 individual worksheet tabs from 1 Excel workbook to individual workbooks? 1 workbook for each tab in main workbook.

DETAILS:
My main workbook has a pivot table with a Department filter. I then used Pivot Table Tools > Analyze > Options > Show Report Filter Pages to create individual worksheets for each department's data.

Now need to place each department's report into a separate workbook.

Thanks,
Bob
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Saves each sheet as an .XLSX file in the same location as the main workbook :

VBA Code:
Option Explicit

Sub SplitWorkbook()
    Dim sDate As String
    Dim ws As Worksheet
    Dim wb1 As Workbook, wb2 As Workbook
    Dim sPath1 As String, sFile2 As String
    
    Application.ScreenUpdating = False
    
    Set wb1 = ThisWorkbook
    
    If Month(Now) - 1 = 0 Then
        sDate = Format(DateSerial(Year(Now) - 1, 12, 1), "mmmm yyyy")
    Else
        sDate = Format(DateSerial(Year(Now), Month(Now) - 1, 1), "mmmm yyyy")
    End If
        
        
    sPath1 = wb1.Path & Application.PathSeparator
        
    For Each ws In wb1.Worksheets
        sFile2 = sDate & " " & ws.Name
        ws.Copy
        Set wb2 = ActiveWorkbook
        
        On Error Resume Next
        Kill sPath1 & sFile2 & ".xlsx"
        On Error GoTo 0
        
        wb2.SaveAs Filename:=sPath1 & sFile2, FileFormat:=xlOpenXMLWorkbook
    
        wb2.Close (False)
    
        wb1.Activate
    
    Next

    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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