Unable to select a sheet while copy pasting data

Pranesh

Board Regular
Joined
Jun 29, 2014
Messages
219
Hi All,

Im trying to copy a data from 1st excel to 2nd excel. While im about to select a sheet in 2nd file im getting "Subscript out of range" as error. I have used the same code earlier for several other excels but I haven't get this kind of error. Can someone help me to fix this. Below is my code.

Im getting error exactly here "Sheets("Addition").Select"

Code:
Sub Template()
Application.ScreenUpdating = False
Dim twb As Workbook
Dim tw As ThisWorkbook

Set tw = ThisWorkbook
Sheet3.Select
Range("F10").Select
TempSBU = Selection.Value
Workbooks.Open Filename:=TempSBU
Set twb = ActiveWorkbook
tw.Activate
Sheet4.Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
twb.Activate
Sheets("Addition").Select
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Probably means that you don't have a sheet called "Addition" in the workbook that was opened by the code.
 
Upvote 0
Probably means that you don't have a sheet called "Addition" in the workbook that was opened by the code.

Hi Fluff - I have a sheet called "Addition" and also tried to call it out as sheet1.select but getting the same error.
 
Upvote 0
Double check the spelling, including any leading/trailing spaces.
You cannot use Sheet1.Select as you can only use the codename like that for sheets in ThisWorkbook
 
Upvote 0
Double check the spelling, including any leading/trailing spaces.
You cannot use Sheet1.Select as you can only use the codename like that for sheets in ThisWorkbook

Thanks Fluff.. There was a space at the end and that is why it didn't work. To avoid this confusion can you please let me know how to use Sheet1.Select
 
Upvote 0
You can only use the sheet codenames in that manner for sheets in the workbook containing the code.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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