Moving some Worksheets to their Own Workbooks

markf5998

Board Regular
Joined
Jan 13, 2011
Messages
103
I have a workbook that has about 100 sheets, some of which are called "Fact Sheet 1", "Fact Sheet 2"..."Fact Sheet 50"

I'm trying to make each "Fact Sheet" its own file *if* cell C11 on the sheet contains any text.

I have written code to do it one sheet at a time, but the problem is when the new workbook is created, the original containing the other 49 sheets I want to re-save is closed.

It would be nice if this could all happen at once. Any ideas to get me going in the right direction?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this
Code:
Dim oneSheet as WorkSheet

For each oneSheet in ThisWorkbook.Worksheets
    With oneSheet
        If .Name Like "Fact Sheet *" And Len(CStr(.Range("C11"))) > 0 Then
            oneSheet.Copy
        End If
    End With
Next oneSheet
 
Upvote 0
Thanks for the reply!

I'm still a beginner when it comes to VBA, so a question, if you don't mind:

I can see what it's doing and substitute my "save sheet as new workbook" code in place of "onesheet.copy", but how do I tell it to just create the new file and not colse the original? Currently, it creates the new workbook, makes it the active workbook, and closes the original file. It looks like your code will work, as long as the original file stays open.

Thanks again for your help!
 
Upvote 0
Actualy the code I posted does NOT save the newly made workbooks. To do that, one would need to know where to save it. If you aren't picky about that, you could use this, if you were picky, you could use SaveAs and specify a filepath.

Code:
Dim oneSheet as WorkSheet

For each oneSheet in ThisWorkbook.Worksheets
    With oneSheet
        If .Name Like "Fact Sheet *" And Len(CStr(.Range("C11"))) > 0 Then
            oneSheet.Copy
            ActiveWorkbook.Save
            ActiveWorkbook.Close
        End If
    End With
Next oneSheet
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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