using the FOR I = statement

G

Guest

I have 16 variables labeled say var1, var2 var3 etc, I want to place into
these variables a number depending on a different criteria, I don't have to
fill all 16 variables, I may only need to fill 6 one time or 10 another time.
I would like to use the For = 1 to (number needed) but haven't been able to
get the variables to come out correct.
I could do it with an If statement but would need 16 of them as it depends
on a number from 2 - 16.
I'm able to build the variable using var & I, where I changes with each
loop, but I have been able to put the right number into that variable and
keep it there so that say var1 = 93.34, and var2 = 83.33 etc.
This probably isn't very clear but if someone has some examples for the use
of the for I = 1 to statement that works with variables I could probably use
them as a sample.
Thanks for your help, everybody is always very helpful.

Tom
 
R

Rob Parker

I suggest you'll find this easier if, rather than using 16 variables, you
use a single variant array. Then you can use code such as this:

Public Sub Test()
Dim i As Integer
Dim var(16) As Variant

For i = 1 To 3
var(i) = i * 42.12345
Debug.Print "Var(" & i & ") = " & var(i)
Next i
End Sub

HTH,

Rob
 

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