array question

B

Brent

Want to do something like:

arrayvar = ("alpha","beta","delta")
For B = A(1) to A(3)
.......

Is this possible? Or do I have to do:
arrayvar = ("alpha","beta","delta")
For count = 1 to 3
B = A(count)

Also, for 3 variables, is this method faster than a if then else procedure?
Thank you.

Brent
 
B

Bob Umlas

What's "A"?
How about:
For each thing in array("alpha","beta","delta")
'use "thing" here...
Next
Bob Umlas
Excel MVP
 
B

Brent

sorry meant:

arrayvar = ("alpha","beta","delta")
For B = arrayvar(1) to arrayvar(3)

would the "for each" be quicker than an "if than else" for three variables?
Thank you.

Brent
 
D

Dave Peterson

Did you mean something like:

dim ArrayVar as variant
dim iCtr as long
arrayvar = array("alpha","beta","delta")
for ictr = lbound(arrayvar) to ubound(arrayvar)
msgbox arrayvar(ictr)
next ictr
 
D

Dana DeLouis

Others gave you the proper use of UBound / LBound.
Just to add if you wish a simple "1 to 3" as in your example:

Sub Demo()
Dim V As Variant
Dim J As Long
' 0-Based
V = Array("Alpha", "Beta", "Delta")
' 1-Based
With WorksheetFunction
V = .Transpose(.Transpose(V))
End With

For J = 1 To 3
MsgBox Format(J, "##: ") & V(J)
Next J
End Sub
 

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