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
I encountered the same behavior when getting an Excel range within a range in VB.Net. Tim's answer solved the weird behavior. At first I though it had something to do with the use of With
but I guess it had something to do with the double relative referencing of dot notation as Tim had suggested.
Public Sub SomeMergingFunction(ByRef inputRange As Excel.Range)
With inputRange
Debug.Print(.Address) ' $A$4:$A$130 correct
Debug.Print(.Cells(1, 1).Address) ' $A$4 correct
Debug.Print(.Range(.Cells(1, 1), .Cells(1, 1)).Address) ' $A$7 wrong
Debug.Print(.Parent.Range(.Cells(1, 1), .Cells(1, 1)).Address) ' $A$4 correct
End With
End Sub