Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Re-assigning the value of a variable for a for loop from
Afternoon all,
I have a for loop that is initialised but then needs to change the value for the number of loops: ######################### For iQaRunDbaseSheet = 1 To (iArraySize + 1) ............ If i 1 Then iMaxSheet = Worksheets.Count Worksheets.Add after:=Sheets(iMaxSheet) iArraySize = iArraySize + 1 End If ################################################# Whilst the actual variable changes its value, the for loop only executes the number of times that was initially assigned to it. Is there anyway I can get the for loop to run the number of times i want it to rather than the initial value ? Thanks, Mike. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Re-assigning the value of a variable for a for loop from
You're not able to do this. The convention of a FOR NEXT loop is that it
knows in advance how many iterations to perform. You can quit prematurely but not change the boundaries. These are setup once and once only. What you need to be doing is using a DO WHILE/UNTIL type construct. This way you loop while a condition is not been met. -- Regards, Bill Lunney www.billlunney.com "Mike Berry" wrote in message ... Afternoon all, I have a for loop that is initialised but then needs to change the value for the number of loops: ######################### For iQaRunDbaseSheet = 1 To (iArraySize + 1) ........... If i 1 Then iMaxSheet = Worksheets.Count Worksheets.Add after:=Sheets(iMaxSheet) iArraySize = iArraySize + 1 End If ################################################# Whilst the actual variable changes its value, the for loop only executes the number of times that was initially assigned to it. Is there anyway I can get the for loop to run the number of times i want it to rather than the initial value ? Thanks, Mike. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Assigning values to a variable set | Excel Discussion (Misc queries) | |||
Loop with variable name? | Excel Discussion (Misc queries) | |||
Assigning a variable | Excel Worksheet Functions | |||
Assigning Variable Range | Excel Discussion (Misc queries) | |||
Insert Variable Number of Rows; With Loop | Excel Worksheet Functions |