ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   array question (https://www.excelbanter.com/excel-programming/387409-array-question.html)

Brent

array question
 
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

Bob Umlas

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

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




Brent

array question
 
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


"Bob Umlas" wrote:

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

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





Dave Peterson

array question
 
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


Brent wrote:

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

"Bob Umlas" wrote:

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

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





--

Dave Peterson

Dana DeLouis

array question
 

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

--
HTH :)
Dana DeLouis
Windows XP & Office 2007


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


"Bob Umlas" wrote:

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

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








All times are GMT +1. The time now is 02:16 PM.

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