Setting range by cells fails
Hello,
Cells refers to the active sheet. If your active sheet is not
worksheet("test"), an error will occur.
Try this:
With Worksheets("test")
Set RNG = Range(.Cells(1, 1), .Cells(1, 1))
End With
OR
Set RNG = Range(Worksheets("test").Cells(1, 1), _
Worksheets("test").Cells(3, 3))
Andrew a écrit :
Hello,
I have been trying to set a range using the following code:
Dim RNG as Range
Set RNG = worksheets("test").Range(cells(1,1),cells(10,10))
This fails with an error 1004
but if I use this code
Dim RNG as Range
Set RNG = worksheets("test").Range("A1:J10)
The code works.
This is the same range, why won't the compiler accept the first code?
thanks,
andy
|