Copy Worksheets to New Book

N

Nigel

I recoreded a macro and it worked fine, I then copied the coed into a
function and it fails here is the code

ActiveWorkbook.Sheets(Array("Airgas", "Praxair", "Other G1 Cust", "T1 Cust",
"Other Cust")).Select
ActiveWorkbook.Sheets("Other Cust").Activate

ActiveWorkbook.Sheets(Array("Airgas", "Praxair", "Other G1 Cust", "T1
Cust", "Other Cust")).Copy Before:=Workbooks(NEWWORKSHEET).Sheets(11)
application.Run Range("ScOnWindow")
ActiveWorkbook.Sheets(Array("Airgas", "Praxair", "Other G1 Cust", "T1
Cust", "Other Cust")).Select
ActiveWorkbook.Sheets("Airgas").Activate
Range("A1").Select
ActiveWorkbook.Sheets("Price SRP1 by Req Date").Select

it fails on this line
ActiveWorkbook.Sheets(Array("Airgas", "Praxair", "Other G1 Cust", "T1
Cust", "Other Cust")).Copy Before:=Workbooks(NEWWORKSHEET).Sheets(11)

with the error message subscript out of range. (NEWWORKSHEET is the name of
the book the sheets are being copied to and is declared earlier in the code)

Any solutions would be helpful

thanks in advance
 
P

Patrick Molloy

you're trying to copy before sheet 11. Are ther 11 sheets in the target
workbook already?

maybe replace
Before:=Workbooks(NEWWORKSHEET).Sheets(11)

with

Before:=Workbooks(NEWWORKSHEET).Sheets(
Workbooks(NEWWORKSHEET).worksheets.count)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top