Copying Worksheets

Hannah

Board Regular
Joined
Aug 20, 2002
Messages
51
I want to copy a whole worksheet from a workbook that is not active into an active workbook, but i'm getting the error "subscript out of range" This is what i've done....any suggestions?

Workbooks("c:timesheetsexpenditureconsulting_tues.xls").Sheets(1).Copy _
after:=ActiveWorkbook.Sheets(2)
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello,

You don't need the full path of the workbook in question, just the name. This should work:-

Workbooks("consulting_tues.xls").Sheets(1).Copy _
after:=ActiveWorkbook.Sheets(2)
 
Upvote 0
Hi Hannah,
The code that Dan wrote worked on my excel.(XL97 and XL2000)
Would you confirm your name of the workbook again? And please confirm your active workbook has more than 2 sheets.

HTH
 
Upvote 0
have more than 2 sheets and file name is correct....what else can i do??????

help...this has been driving me nuts for the last 2 days!
 
Upvote 0
On 2002-08-21 16:42, Hannah wrote:
I want to copy a whole worksheet from a workbook that is not active into an active workbook, but i'm getting the error "subscript out of range" This is what i've done....any suggestions?

Workbooks("c:timesheetsexpenditureconsulting_tues.xls").Sheets(1).Copy _
after:=ActiveWorkbook.Sheets(2)

This might be a stupid question, but is the consulting_tues workbook actually open when you're running the macro?
 
Upvote 0
nope...i don't want it to be....in a perfect world i'll be copying over all these sheets into one workbook and only actually have that workbook open....am i making things too difficult for myself (considering 2 weeks ago i didn't even know what sum was??)
 
Upvote 0
ah see what u mean.....opens when the workbook is active......is there anyway i can do it without doing this or will i always have to open them (or something like ....("consulting_tues.xls").activate???)

i really have no idea.....
 
Upvote 0
persistant arn't i????

anyway, tried my own suggestion of activate before the other code and we're back to the same old error....this is taking much too long....
 
Upvote 0
You can't activate a workbook that isn't open. Open it first, and then copy. E.g.

Code:
Sub Test()
Workbooks.Open("c:timesheetsexpenditureconsulting_tues.xls").Sheets(1).Copy _
after:=ActiveWorkbook.Sheets(2)
Workbooks("consulting_tues.xls").Close False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,579
Messages
6,173,171
Members
452,504
Latest member
frankkeith2233

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