ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I find the number of elements in an Array of Strings? (https://www.excelbanter.com/excel-programming/332046-how-do-i-find-number-elements-array-strings.html)

BeefmanSteve

How do I find the number of elements in an Array of Strings?
 
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.

Alan Beban[_2_]

How do I find the number of elements in an Array of Strings?
 
BeefmanSteve wrote:
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

Norman Jones

How do I find the number of elements in an Array of Strings?
 
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

---
Regards,
Norman



"BeefmanSteve" wrote in message
...
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.




Dave Peterson[_5_]

How do I find the number of elements in an Array of Strings?
 
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




BeefmanSteve wrote:

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.


--

Dave Peterson

Bob Phillips[_6_]

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

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

--

HTH

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


"BeefmanSteve" wrote in message
...
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.




Ron Rosenfeld

How do I find the number of elements in an Array of Strings?
 
On Thu, 16 Jun 2005 16:08:01 -0700, BeefmanSteve
wrote:

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


All times are GMT +1. The time now is 01:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com