setting range fails

cedarhay

New Member
Joined
Jan 25, 2008
Messages
7
Hi all,

I suspect something fairly obvious, but can't see it.

With the following snippet
Dim destrange As Range
dim destsh as worksheet
Set destsh = Workbooks(myfilename).Sheets(1)
..some code
a) Set destrange = destsh.Range("a11:d19")
b) Set destrange = destsh.Range(Cells(11, 1), Cells(19,4))

Why does (a) work, and (b) fail with messages
"Runtime error '1004'
Method 'Range' of object '_Worksheet' failed


Many thanks
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
When you specify the sheet on the Range, you must also specify it on both Cells within the range...

Try

Set destrange = destsh.Range(destsh.Cells(11, 1), destsh.Cells(19,4))


Hope that helps.
 
Upvote 0
Thanks for the tip, unfortunately it didn't work

I found that if I activated the workbook first the code worked ok
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

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