Cells reference to another worksheet

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,341
In my code I have the following two lines:
Sheets("PersStore").Range("A2:A84").Copy
Sheets("PersStore").Range(Cells(2, 1), Cells(84, 1)).Copy
The code breaks at the second line with the message "Run-time error 1004 Application-defined or object-defined error"
The second line runs if I first make PersStore the active worksheet. I want to use the second line, but I don't want to have to activate the other worksheet. Can anyone point me in the right direction?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
change it to
VBA Code:
Sheets("PersStore").Range(Sheets("PersStore").Cells(2, 1), Cells(84, 1).Address).Copy
 
Upvote 0
Thanks Bebo, but I'm curious to know why the Cells method doesn't work?
Assume active sheet is Sheet1
With this line
VBA Code:
Sheets("PersStore").Range(Cells(2, 1), Cells(84, 1)).Copy
excel think Cells(2, 1) is cell A2 of current sheet "Sheet1"

Should be:
VBA Code:
Sheets("PersStore").Range(Sheets("PersStore").Cells(2, 1), Sheets("PersStore").Cells(84, 1)).Copy

or shorter:
VBA Code:
With Sheets("PersStore")
    .Range(.Cells(2, 1), .Cells(84, 1)).Copy
End With
with the dot "." present Sheets("PersStore") properties
 
Upvote 0
Solution

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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