0

I have been creating Ranges with Cells for a while but always on the selected worksheet. I use the following syntax:

Dim r as Range
Set r = Range(Cells(1, 1), Cells(4, 2))

This has always worked.

I am not trying to select a range on a different sheet using the following syntax:

Dim r as Range
Set r = Worksheets("working").Range(Cells(1, 1), Cells(4, 2))

and get the following Error: "Application-defined or Object-defined error".

In the immediate Window, I am finding something very interesting.. assuming "r" has been dimmed and that the selected worksheet is (1) (not "working".. which is (2))

r = Worksheets("working").Range("A1:D2")   <<< THIS WORKS
r = Worksheets("working").Range(Cells(1, 1), Cells(4, 2))   << ERROR
r = Range(Cells(1, 1), Cells(4, 2)) <<< THIS WORKS (on selected sheet).

So I'm just confused and have been combing thru SO and other sites. I know I'm doing something obviously wrong... can someone help?

Thanks.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Ed Landau
  • 966
  • 2
  • 11
  • 24

1 Answers1

1

Qualify all objects (Including Cells).

Dim ws as Worksheet: Set ws = ThisWorkbook.Sheets("working")

Set r = ws.Range(ws.Cells(1, 1), ws.Cells(4, 2))
urdearboy
  • 14,439
  • 5
  • 28
  • 58