Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA using ubound on a multidimensional array

Tags:

arrays

excel

vba

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?

like image 347
brietsparks Avatar asked Oct 30 '14 02:10

brietsparks


People also ask

How does UBound work in VBA?

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.

How do I ReDim preserve a two dimensional 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.

What does UBound return?

The UBound Function returns the largest subscript of the specified array. Hence, this value corresponds to the size of the array.


1 Answers

ubound(arr, 1)  

and

ubound(arr, 2)  
like image 171
Maksim Satsikau Avatar answered Sep 23 '22 05:09

Maksim Satsikau