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!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi & welcome to MrExcel.
Try
VBA Code:
    Sheets(Array("Lookups", ws.Name)).Copy
 
Upvote 0
Solution
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.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

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