I saw quite a number of questions/answers along these lines, but after reading a bunch of them, I'm still confused. I'm sorry if this is the nᵗʰ time a variant of this has been asked.
I can't figure out why this code dies on line 5 with a "subscript out of range" error in VBA (Excel for Mac v16.38):
Public Function array_test()
Dim arr As Variant
Dim array_slice As Variant
arr = Range("TestData!B27:F32").Value2
array_slice = arr(2) 'dies here with error 9
array_test = array_slice
End Function
Looking at the values pane, arr is clearly a Variant/Variant(1 to 6, 1 to 5) with all the expected data. There is nothing special about the cells, just non-formula data.
Even if I change the declarations to arr() and array_slice() or remove ".Value2", I get the same results. Even trying Application.WorksheetFunction.Index(arr, 2) rather than arr(2) gets me nowhere.
What am I missing?
P.S. I'm a C/Python programmer normally, so I'm thinking of arrays in those terms.
array_slice = arr(2,1)- JvdV