Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Copy Worksheets to New Book

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 Befo=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 Befo=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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Copy Worksheets to New Book

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

maybe replace
Befo=Workbooks(NEWWORKSHEET).Sheets(11)

with

Befo=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 Befo=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 Befo=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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving worksheets to another book - 2nd book will not appear jb0100 Excel Discussion (Misc queries) 2 March 18th 09 03:09 PM
copy worksheets to new book without linking to original book Lori Excel Discussion (Misc queries) 2 March 4th 09 04:46 PM
How many worksheets in a book? Kaitlin.uk Excel Discussion (Misc queries) 3 January 25th 07 04:04 AM
Copy worksheets from one book to another Grotifant Excel Programming 1 February 18th 05 08:54 AM
Copy Worksheets from one book to another? Jonx[_4_] Excel Programming 5 August 17th 04 10:55 AM


All times are GMT +1. The time now is 01:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"