Is there a way to index a named range like an array? For example, in a spreadsheet I name cells F1 to F5 as "DaRange" and in VBA I want to set the second element (which is F2) to 5. Is there a way to do the following?
Range("DaRange")[2] = 5
Thanks
Printable View
Is there a way to index a named range like an array? For example, in a spreadsheet I name cells F1 to F5 as "DaRange" and in VBA I want to set the second element (which is F2) to 5. Is there a way to do the following?
Range("DaRange")[2] = 5
Thanks
With "F1:F5" has been named as "DaRange", you can use:
Range("DaRange")(2) = 5
Index number 2 refers to the second cell in the range.
An example in general case: Cell index numbers will be counted from left-to-right and top-to-bottom.
Code:Dim MyRange As Range, i As Long
Set MyRange = Range("C3:E10")
Debug.Print MyRange.Cells(2, 2).Address '-- $D$4
Debug.Print MyRange(5).Address '-- $D$4
For i = 1 To MyRange.Cells.Count
Debug.Print "MyRange(" & i & ") : " & MyRange(i).Address
Next