I am trying to write a simple array, I have written many arrays but I don't understand why on this occasion I am not getting the desired result.
Below is the code I am using, so I am generating a report name and putting them in an array to retrieve later on by referencing the index number,
So the debug within the loop works and I can see theem being stored, when I am outside the loop cannot retrieve it so cannot recall.
Any ideas?
For i = 1 To num
reportname = API & SetPeriod & APIEnd
ReDim retrieve(1 To i)
retrieve(i) = reportname
SetPeriod = SetPeriod + 1
Debug.Print retrieve(i)
Next i
ReDim retrieve(1 To 4)
Debug.Print retrieve(2)
Debug.Print retrieve(2)
ReDim retrieve(1 To i)in the loop? Why not simplyReDim retrieve(1 To num)prior to the loop? (ReDim Preservein the loop would probably give you the results that you expect but would be very inefficient sinceReDim Preserveis an expensive operation).