Forum Discussion
Trouble with addressing a "jagged array" in Excel VBA - subscript out of range
I have been troubled with a subscript out of range issue. At the very least I am looking to be able to address an array of arrays, apparently called a jagged array.
I have a simple example (chatGPT) that works wonderfully and when I look at the structure of arr_filteredData, the example matches my production array. When I alter the simple example to pass down the arr_filteredData from the calling SUB, I end up receiving a subscript out of range error 9.
The one difference I noticed is that the sample starts at base 0 and the one I have is starting at base 1. and mine looks like arr_filteredData (1,1) and the sample looks like arr_filteredData(0)(0). I think this is the primary issue. How should I be addressing the production array?
Unfortunately, I can't supply data to go along with this example. The code snippet is attached.
Alter the sample routine with the production array arr_filteredData
- peiyezhuBronze Contributorhttps://learn.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/subscript-out-of-range-error-9#:~:text=This%20error%20has%20the%20following%20causes%20and%20solutions:%20You
Which line does the codes stop?
If with your convenience,please post codes in text instead of screenshot and some dummy data for testing. arr_filteredData is a one-dimensional array.
Use
For i = LBound(arr_filteredData) To UBound(arr_filteredData)