ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating an array of strings (https://www.excelbanter.com/excel-programming/424863-creating-array-strings.html)

John

Creating an array of strings
 
How do I create a list of strings that I can cycle thru via a for loop
something like this. I can't get the syntax right, not being much of a VB
guy.

Dim List1() as String
List1 = {"aaa", "bbb", "ccc"}
For i = 1 to 3
MsgBox List1(i)
Next

I appreciate your help, -John

joel

Creating an array of strings
 
List need to be a variant or not declared. Arrays by default start at 0 index

Sub test()

Dim List1
List1 = Array("aaa", "bbb", "ccc")
For i = 0 To 2
MsgBox List1(i)
Next

End Sub


"John" wrote:

How do I create a list of strings that I can cycle thru via a for loop
something like this. I can't get the syntax right, not being much of a VB
guy.

Dim List1() as String
List1 = {"aaa", "bbb", "ccc"}
For i = 1 to 3
MsgBox List1(i)
Next

I appreciate your help, -John



All times are GMT +1. The time now is 06:21 AM.

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