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

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.
 
A

Alan Beban

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
 
N

Norman Jones

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
 
D

Dave Peterson

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
 
B

Bob Phillips

For i = LBound(ary) To UBound(ary)
Debug.Print ary(i)
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
R

Ron Rosenfeld

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
 

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