PC Review


Reply
Thread Tools Rate Thread

Copy Worksheets to New Book

 
 
Nigel
Guest
Posts: n/a
 
      20th Oct 2009
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
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      21st Oct 2009
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)


"Nigel" wrote:

> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving worksheets to another book - 2nd book will not appear jb0100 Microsoft Excel Misc 2 18th Mar 2009 03:09 PM
copy worksheets to new book without linking to original book Lori Microsoft Excel Misc 2 4th Mar 2009 04:46 PM
Copy data from multiple worksheets to worksheets in a number of other spreadsheets SteveH Microsoft Excel Discussion 5 6th Nov 2006 06:59 PM
Re: Copy worksheets from one book to another Ajtb Microsoft Excel Programming 0 18th Feb 2005 08:54 AM
Copy Worksheets from one book to another? Jonx Microsoft Excel Programming 5 17th Aug 2004 10:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:08 PM.