Macro for - Selecting & copying multiple tabsheets to a new excel workbook

ya_aashiq

New Member
Joined
Jan 8, 2017
Messages
5
Hello

I need a code for selecting and copying specific multiple worksheets. For example if a workbook has 10 worksheets, I need to select 5 of them based on their name and copy the complete worksheets to a new workbook.

Can anyone help plz?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this code
Code:
Sub Test()    Dim ArrSheetToCopy, I As Long


    ArrSheetToCopy = Array("1", "2") 'Sheet Names


    Application.ScreenUpdating = False
        With Workbooks.Add
            Application.DisplayAlerts = False
            For I = 1 To (.Sheets.Count - 1)
                .Sheets(.Sheets.Count).Delete
            Next I
            .Sheets(.Sheets.Count).Name = String$(20, "Z")
            
            For I = 0 To UBound(ArrSheetToCopy)
                ThisWorkbook.Sheets(ArrSheetToCopy(I)).Copy Before:=.Sheets(.Sheets.Count)
            Next I
            .Sheets(.Sheets.Count).Delete
            Application.DisplayAlerts = True
            
            .SaveAs ThisWorkbook.Path & "\Yasser_" & Format(Date, "yyyymmdd") & "_" & Format(Time, "hhmmss") & ".xlsm", xlOpenXMLWorkbookMacroEnabled
            .Close
        End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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