How do I find the number of elements in an Array of Strings?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm programming VBA in Excel 2003.
I wish to index through a loop for each element in an array. But I need to
refer to the elements by their index number, not their value as a string.
How can I find the number of elements in an array of strings?
Thanks.
 
BeefmanSteve said:
I'm programming VBA in Excel 2003.
I wish to index through a loop for each element in an array. But I need to
refer to the elements by their index number, not their value as a string.
How can I find the number of elements in an array of strings?
Thanks.
UBound(MyArray) - LBound(MyArray) + 1

Alan Beban
 
Hi BeefmanSteve,

Sub Tester()
Dim Arr As Variant
Dim NumOfElements As Long

Arr = Array("aaa", "bbb", "cccc")
NumOfElements = UBound(Arr) - LBound(Arr) + 1
MsgBox NumOfElements

End Sub
 
dim myArr as variant
dim iCtr as long
myarr = array("a","qwer","qwerqwer","asdf")

for ictr = lbound(myarr) to ubound(myarr)
msgbox myarr(ictr)
next ictr
 
For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
I'm programming VBA in Excel 2003.
I wish to index through a loop for each element in an array. But I need to
refer to the elements by their index number, not their value as a string.
How can I find the number of elements in an array of strings?
Thanks.

Look at the LBound and UBound functions.


--ron
 
Back
Top