Split workbook into files

DicksonKwok

New Member
Joined
Nov 3, 2022
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hi all,

I wish to split the workbook (contain some input spreadsheet and a guideline page named as "Guideline")

I got the VBA code to split all the spreadsheets into files, but I am curious whether there is a code can save split the workbook with the targeted input spreadsheet name PLUS a guideline page?

Look like:

5 Spreadsheets of the Master File:
Consolidated Page
Finance
HR
CEO
Supporting

I want the output to be 3 separate file:
File name: Finance
Cover spreadsheet(s): Finance, Supporting
File name: HR
Cover spreadsheet(s): HR, Supporting
File name: CEO
Cover spreadsheet(s): CEO, Supporting

Thanks in advance.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi DicksonKwok,

what about

VBA Code:
Sub MrE1221063_161330D()
'https://www.mrexcel.com/board/threads/split-workbook-into-files.1221063/

Dim varSheets       As Variant      'array of sheets to copy
Dim varReports      As Variant      'array of new sheets to create
Dim lngCounter      As Long         'for looping through the

varReports = Array("Finance", "HR", "CEO")

For lngCounter = LBound(varReports) To UBound(varReports)
  Select Case varReports(lngCounter)
    Case "Finance"
      varSheets = Array("Guideline", "Finance", "Supporting")
    Case "HR"
      varSheets = Array("Guideline", "HR", "Supporting")
    Case "Finance"
      varSheets = Array("Guideline", "CEO", "Supporting")
    Case Else
  End Select
  If IsArray(varSheets) Then
    Sheets(varSheets).Copy
    ActiveWorkbook.SaveAs Application.DefaultFilePath & "\" & varReports(lngCounter) & Format(Now, "_yymmdd_hhmmss") & _
          ".xlsx", FileFormat:=51
    ActiveWorkbook.Close True
    Erase varSheets
  End If
Next lngCounter

End Sub

Code will create new workbooks with a Date/Time stamp added to the filename as macrofree workbooks in the folder which is set as standard.

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

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