Hello and Macro Help

oespresso

New Member
Joined
Jul 15, 2014
Messages
2
Hello,

My first on this forum!

I'm quite new to VBA. Having some trouble trying to copy sheets. Not quite sure what's going wrong here:

I have a template workbook (checker.xlsm) which has 2 sheets (FormatControl, ErrorControl), both of which I want to copy to an Excel workbook that the user selects.

So far I have the code below:

Code:
Sub MoveSheets()
    
targetWB = Application.GetOpenFilename()
Workbooks.Open (targetWB)

Windows("checker.xlsm").Activate
    Sheets(Array("ErrorControl", "FormatControl")).Select
    Sheets("FormatControl").Activate
    Sheets(Array("ErrorControl", "FormatControl")).Copy Before:=Workbooks( _
        targetWB).Sheets(1)


End Sub

Unfortunately I get run time error '9' - subscript out of range in the last part.

Where am I going wrong?

Help greatly appreciated!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try

Code:
Sub MoveSheets()
Dim targetWB As String, wb As Workbook
targetWB = Application.GetOpenFilename()
Set wb = Workbooks.Open(targetWB)

Windows("checker.xlsm").Activate
Sheets(Array("ErrorControl", "FormatControl")).Copy Before:=wb.Sheets(1)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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