Array Size

S

Srinath

Hello again,

How can i get the Size of the Array ? that is I have an Array which is
dynamic and at the end i would like to know the number of elements in the
array and then do further processing.

Regards,
SSR
 
K

Keith Willshaw

Srinath said:
Hello again,

How can i get the Size of the Array ? that is I have an Array which is
dynamic and at the end i would like to know the number of elements in the
array and then do further processing.

Regards,
SSR

Use the Ubound function

Dim Upper
Dim MyArray(1 To 10, 5 To 15, 10 To 20) ' Declare array variables.
Dim AnyArray(10)
Upper = UBound(MyArray, 1) ' Returns 10.
Upper = UBound(MyArray, 3) ' Returns 20.
Upper = UBound(AnyArray) ' Returns 10.

Keith
 
S

Srinath

Thanks


Srinath said:
Hello again,

How can i get the Size of the Array ? that is I have an Array which is
dynamic and at the end i would like to know the number of elements in the
array and then do further processing.

Regards,
SSR

Use the Ubound function

Dim Upper
Dim MyArray(1 To 10, 5 To 15, 10 To 20) ' Declare array variables.
Dim AnyArray(10)
Upper = UBound(MyArray, 1) ' Returns 10.
Upper = UBound(MyArray, 3) ' Returns 20.
Upper = UBound(AnyArray) ' Returns 10.

Keith
 
C

Chip Pearson

SSR,

Use something like

NumElements = UBound(Arr) - LBound(Arr) + 1


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
M

Myrna Larson

If by Size he means the count of the number of elements (rather than the index of the last
element) you also need the LBound function. UBound gives the number of elements only if the
lower bound is 1.

NumElements = Ubound(Ary) - LBound(Ary) + 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top