TheRedCardinal
Active Member
- Joined
- Jul 11, 2019
- Messages
- 250
- Office Version
- 365
- 2021
- Platform
- Windows
I have a really simple code:
The size of my arrays (as per the locals window) are:
I know that the counter will loop to 15 but then shouldn't execute the code inside the For/Next loop.
I use these loops all the time and haven't seen this issue before.
But now my counter is 15 and it's trying to populate my FinalArray at (1,15) which obviously doesn't exist.
Have I done something very stupid?
****Update****
I have just stepped through and it's even more strange. When it gets to the code above, Counter is Empty.
In the 1st iteration of the loop, it is set to 14, and not 1?
****Update 2****
I went back to basics and declared my variables (I didn't originally because this is just testing code) and declared Counter as Long and now it seems to work ok, but why?
VBA Code:
For Counter = 1 To UBound(SCols, 1)
FinalArray(1, Counter) = SCols(Counter, 1)
Next Counter
The size of my arrays (as per the locals window) are:
- Final Array, 1 to 133, 1 to 14
- SCols, 1 to 14, 1 to 3
I know that the counter will loop to 15 but then shouldn't execute the code inside the For/Next loop.
I use these loops all the time and haven't seen this issue before.
But now my counter is 15 and it's trying to populate my FinalArray at (1,15) which obviously doesn't exist.
Have I done something very stupid?
****Update****
I have just stepped through and it's even more strange. When it gets to the code above, Counter is Empty.
In the 1st iteration of the loop, it is set to 14, and not 1?
****Update 2****
I went back to basics and declared my variables (I didn't originally because this is just testing code) and declared Counter as Long and now it seems to work ok, but why?