Split all sheets into separate workbooks, but always include "sheet2" with them

Heelertreats

New Member
Joined
Jan 8, 2021
Messages
6
Platform
  1. Windows
Noob here. I've seen some questions that are close to this (split sheets two at a time, etc), but I haven't found exactly what I need yet. Hoping y'all can help me out.

I have a button set up that dynamically creates new worksheets based on data in sheet3. I have a second button that splits each of those worksheets into its own separate workbook. What I lack is that the new workbooks should always include sheet2 as well as the dynamically generated sheet.

Example:
Original workbook sheets: Template | Lookups | Master
After I enter values in sheet Master: Template | Lookups | Master | new1 | new2 | new3 | etc
After I hit my "split" button, all of the new workbooks have only one tab: new1 or new2 or new3 etc

Instead, I'd like the sheet Lookups to be included in the split with each of the other new sheets, such that each new workbook has these sheets: Lookups | new1, or Lookups | new2, or Lookups | new3

I'm going to post my existing VBA . It might not be pretty....

VBA Code:
Sub SplitEachWorksheet()
Dim FPath As String
FPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
    If ws.Name <> "TEMPLATE" And ws.Name <> "Lookups" And ws.Name <> "MASTER" Then
    ws.Copy
    Application.ActiveWorkbook.SaveAs Filename:=FPath & "\" & ws.Name & "_PFC.xlsx"
    Application.ActiveWorkbook.Close False
    End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

I look forward to your insights!
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,833
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
Try
VBA Code:
    Sheets(Array("Lookups", ws.Name)).Copy
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,833
Office Version
  1. 365
Platform
  1. Windows
It will copy the sheets in the order they are in, so if the lookups sheet is before the new sheets, it should be the first sheet in the new workbook.
 

Heelertreats

New Member
Joined
Jan 8, 2021
Messages
6
Platform
  1. Windows
It will copy the sheets in the order they are in, so if the lookups sheet is before the new sheets, it should be the first sheet in the new workbook.
Excellent. Thanks again, and happy New Year!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,833
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,364
Messages
5,595,722
Members
414,013
Latest member
tnobbs

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
Top