I am using following VBA code (MS Excel 2010) to select a range of cells within a given range, to copy and insert the copied cells back into the source range: The range sta
Can confirm this behavior:
Sub Tester()
Dim rng As Range
Set rng = Range("C3:H28")
'This selects E5:F6 (???)
With rng
.Range(.Cells(1, 1), .Cells(2, 2)).Select
End With
'This selects C3:D4 (expected)
With rng
rng.Parent.Range(.Cells(1, 1), .Cells(2, 2)).Select
End With
End Sub
Seems like it may be related to the "double relative" combination of using both .Range
and .Cells
Instead using rng.Parent.Range
and having only the .Cells
be relative to the containing range seems to fix it (and still allows for fully-qualified range references)