Split workbook into multiple files based on value in cell

jmcdoe

New Member
Joined
Apr 5, 2016
Messages
1
Hi,

I am trying to find a way to split a workbook with multiple sheets based on the value in cell A1.

Quick overview of my workbook, cell A1 has the store name, and the worksheet contains 2 reports for each store that I have. So essentially:
Sheet1 = Store1 ReportA
Sheet2 = Store1 ReportB
Sheet3 = Store2 ReportA
Sheet4 = Store2 ReportB
and so on.

I would like to split the workbook into multiple work books based on the store name (value of A1) and automatically save them to a folder. So one file for Store1 with its reports, another for Store2 with its reports, an so on.

Also, the sheet names are like the example above if using value in A1 is not an option.

Can someone please help on this, or possibly direct me to a solution for this?

Thanks.
 
Welcome to MrExcel forums.

Try this (change the destination folder in the code).
Code:
Public Sub Save_Store_Sheet_Pairs()

    Dim destinationFolder As String
    Dim i As Integer
    Dim storeName As String
    
    destinationFolder = "C:\path\to\folder\"        'CHANGE FOLDER
    If Right(destinationFolder, 1) <> "\" Then destinationFolder = destinationFolder & "\"
    
    For i = 1 To Worksheets.Count Step 2
        storeName = Worksheets(i).Range("A1").Value
        Worksheets(Array(Worksheets(i).Name, Worksheets(i + 1).Name)).Copy
        ActiveWorkbook.SaveAs destinationFolder & storeName & ".xlsx"
        ActiveWorkbook.Close SaveChanges:=False
    Next

End Sub
 
Upvote 0

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