Array Size

  • Thread starter Thread starter Srinath
  • Start date Start date
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
 
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
 
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
 
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)
 
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

Back
Top