Macro to copy active sheet and sheet to the right of it to new workbook

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I need a macro that can copy the activesheet and the sheet to the right of it and create a new workbook

Please help if you can
thanks

Tony
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
On a basic level maybe...

Code:
Sub CreateFile()

    Dim wb As Workbook, wbNew As Workbook
    Dim sh As Worksheet
    Dim shIndex As Long, i As Long

    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
    End With


    Set wb = ThisWorkbook
    shIndex = ActiveSheet.Index

    Workbooks.Add
    Set wbNew = ActiveWorkbook

    For i = shIndex To shIndex + 1
        wb.Sheets(i).Copy After:=wbNew.Sheets(wbNew.Sheets.Count)
    Next

    With Application
        .DisplayAlerts = True
        .ScreenUpdating = True
    End With

End Sub
 
Upvote 0
Try this.
Code:
Sheets(Array(ActiveSheet.Name, Sheets(ActiveSheet.Index+1).Name)).Copy
 
Upvote 0
Thanks Norie and Mark,

Both great ideas, I'll play around and see which one suits me best


Thanks

Tony
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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