Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop with Variable name?
Hi. I have 12 variables that are names PN1, PN2, .... PN12
I would like to have a "For - Next" loop that would execute for i = 1 to 12 where "i" would change in the variable name. I cannot figure out how to refer to the variable: For i = 1 to 12 x = PNi + 5 Next i Any help would be appreciated ... Thanks, Mike. (Note I posted this previously in error to the "General" section) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop with Variable name?
Hi Mike
You could use an array variable. Sub Mike() Dim PN(1 To 12) As Long For i = 1 To 12 x = PN(i) + 5 Next End Sub Hopes this helps. --- Per "Mike" skrev i meddelelsen ... Hi. I have 12 variables that are names PN1, PN2, .... PN12 I would like to have a "For - Next" loop that would execute for i = 1 to 12 where "i" would change in the variable name. I cannot figure out how to refer to the variable: For i = 1 to 12 x = PNi + 5 Next i Any help would be appreciated ... Thanks, Mike. (Note I posted this previously in error to the "General" section) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop with Variable name?
Please don't multi post. You have lots of replies in general...
-- HTH... Jim Thomlinson "Mike" wrote: Hi. I have 12 variables that are names PN1, PN2, .... PN12 I would like to have a "For - Next" loop that would execute for i = 1 to 12 where "i" would change in the variable name. I cannot figure out how to refer to the variable: For i = 1 to 12 x = PNi + 5 Next i Any help would be appreciated ... Thanks, Mike. (Note I posted this previously in error to the "General" section) |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loop with Variable name?
I don't think that this sort of dynamic creation of variable name is possible
in VBA. Perhaps you could use an array like this? Sub foo() Dim PN(12) As String Dim i As Integer For i = 0 To 11 PN(i) = i + 5 Next i For i = 0 To 11 MsgBox PN(i) Next i End Sub -Jack Dahlgren "Mike" wrote: Hi. I have 12 variables that are names PN1, PN2, .... PN12 I would like to have a "For - Next" loop that would execute for i = 1 to 12 where "i" would change in the variable name. I cannot figure out how to refer to the variable: For i = 1 to 12 x = PNi + 5 Next i Any help would be appreciated ... Thanks, Mike. (Note I posted this previously in error to the "General" section) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Loop with variable name? | Excel Discussion (Misc queries) | |||
LAST value of loop to be a variable | Excel Programming | |||
loop for-next with variable end | Excel Programming | |||
For Each ... Next loop - need to reference the loop variable | Excel Programming | |||
Loop with variable | Excel Programming |