I declared the array as such Dim rArray() As Variant , but when I try to use the values that are stored in it (as shown below), I get an index error. UBound(rArray) and LBound(rArray) both return 14 and 1, but an error occurs on the Debug.Print line.
If I use the for statement as below
For Each rArr in rArray
then it works without problems, but for the purposes that I create for this array, I need the flexibility to select each element stored in this order, that is, I need to reference them using indexes.
I tried several ways to try and solve it without any luck and spend almost half my day on this problem. Can anyone point out what I need to change to make this work.
Set rng = Range("D4", Range("D4").End(xlDown)) rng.NumberFormat = "0" rArray = rng.Value For x = UBound(rArray) To LBound(rArray) Step -1 Debug.Print rArray(x) Next x
Edit: Another fact worth mentioning is that it is declared and used inside the function, but not passed from or to the function. Is it impossible to declare and use arrays in functions?
arrays vba excel-vba excel
Abhi o.
source share