creating an array from range help
in the first case, the array is always two dimensional:
Sub test()
Dim arr As Variant
Dim i As Long
arr = Range("h2:h11").Value
For i = LBound(arr,1) To UBound(arr,1)
Debug.Print arr(i,1) '<== fix that works
Next
End Sub
The change to Lbound(Arr,1) is for clarity. It would default to that
without the change.
--
Regards,
Tom Ogilvy
"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
i am wondering why this doesn't work:
Sub test()
Dim arr As Variant
Dim i As Long
arr = Range("h2:h11").Value
For i = LBound(arr) To UBound(arr)
Debug.Print arr(i) ' error here
Next
End Sub
but this does:
Sub test()
Dim arr As Variant
Dim i As Long
arr = array("a","b","c")
For i = LBound(arr) To UBound(arr)
Debug.Print arr(i)
Next
End Sub
--
how can i access each element when i create the array from a range?
Gary
|