I have defined a range variable in VBA consisting of a consecutive block of horizontal cells, say,
Dim myRange As Range
Set myRange = Range("A1:H1")
I want to reference the value in the 3rd position in this range to use it in a calculation (I do not need to change the value in this cell). I've found at least 8 different ways to do this:
myRange(1,3)
myRange(3)
myRange(1,3).Value
myRange(3).Value
myRange.Cells(1,3)
myRange.Cells(3)
myRange.Cells(1,3).Value
myRange.Cells(3).Value
Is there any difference between what these different methods are doing? Which one(s) are preferable and why? I'm particularly confused by what happens when I do myRange.Cells
- it seems like that would just return myRange
. It's also not entirely clear to me what type of object is returned by myRange(1,3)
(or myRange(3)
, etc.).