Moving specific worksheets into a new workbook

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

Probably a simple answer to this but seem to be struggling thinking of!

I have a workbook with the following named worksheets:
Balance Sheet Filter
Original Data
Remaining
Filter1
Filter2
Static Data

The number of 'Filter' worksheets varies depending on the existing macro's output.

I wish to cut worksheets 'Filterx' and 'Remaining' into a new workbook but can't think how. Ideally, I want to build up a VBA line of code via a loop process as:

Rich (BB code):
Worksheets(Array("Remaining","Filter1","Filter2" etc)).Select

Which I would then cut and insert into a new workbook.

Any suggestions on how I can do this please?

Thanks,
Jack
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try:

Code:
Sub Test()
    Dim ws As Worksheet
    With ThisWorkbook
        .Worksheets("Remaining").Select
        For Each ws In .Worksheets
            If ws.Name Like "Filter*" Then
                ws.Select False
            End If
        Next ws
        .Windows(1).SelectedSheets.Copy
        .Activate
        .Worksheets(1).Activate
    End With
End Sub

You can use Move instead of Copy if you want.
 
Upvote 0
Hi Andrew,

Can you tell me what's wrong with the code I modified of yours please:

Rich (BB code):
Sub OutputWorkbook()
Dim ws As Worksheet
ActiveSheet.Name = "Remaining"
With ThisWorkbook
    .Worksheets("Remaining").Select
    For Each ws In .Worksheets
        If ws.Name Like "Filter*" Then
            ws.Select False
        End If
    Next ws
    SelectedSheets.Move
End With
End Sub

It fails at the line coloured red. I'd like to move all the sheets into a new workbook, which the user can then save, discard, whatever they desire. Otherwise, thank you, yes it picks up the worksheets I want moving...

Thanks,
Jack
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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