I would like to perform some action on each element of a 2D array where the second dimension of the array varies on each of the first dimensional elements. I would like the loop to skip empty elements.
A 1D array would make it run through the loop without wasting any time on empty elements of the array, but I would like to use a 2D array to make it easier to associate data into a certain group and make the code easier to modify later by somebody else if needed. The 1D array runs much faster than the 2D array.
Application.EnableCancelKey = xlDisabled
On Error Resume Next
For i = 0 To UBound(somearray,1)
For j = 0 To UBound(somearray,2)
perform some action on somearray(i,j)
Next j
Next i
It should be noted that I do get a subscript 9 out of range error without the On Error Resume Next
. I assume this is because it is attempting to perform an action on something that doesn't exist. It works as intended but is just slower.
I apologize if the question is trivial. I wasn't able to find an answer to this and I know nothing about VBA.