Ubound can return the max index value of an array, but in a multidimensional array, how would I specify WHICH dimension I want the max index of?
For example
Dim arr(1 to 4, 1 to 3) As Variant
In this 4x3 array, how would I have Ubound return 4, and how would I have Ubound return 3?
UBOUND or also known as Upper Bound, this function in VBA is used with its opposite function which LBOUND or also known as Lower Bound function, the use of this function is to define the length of an array in a code and as the name suggests UBOUND is used to define the upper limit of the array.
ReDim Preserve any dimension of a 2D Array If you'd like to ReDim Preserve a multidimensional array larger than two-dimensions, your best bet is to construct your array in such a way that only the number of elements in the last dimension will need to be preserved.
The UBound Function returns the largest subscript of the specified array. Hence, this value corresponds to the size of the array.
ubound(arr, 1)
and
ubound(arr, 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With