ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Advance a For Next Loop prior to the Next Statement (https://www.excelbanter.com/excel-programming/336812-how-advance-next-loop-prior-next-statement.html)

ExcelMonkey

How to Advance a For Next Loop prior to the Next Statement
 
I have a For Next Loop. I want to publically define a variable that updates
in another module that increments (1,2,3,4,5 etc). In the loop below I want
to be able to test this public variable to see if it has reached a defined
limit (say 35,0000). When it does, I want to be able to increment the loop
to the next X value. I know I can Exit the loop with "Exit For". But how do
I increment it (i.e. what Next would do) based on my IF value being true
without running the code under the IF statement?

For X = 1 to 10
If PublicVariableCounter = 30,000 Then [increment X to next value]
Call other modules
Next


Thanks

Jake Marx[_3_]

How to Advance a For Next Loop prior to the Next Statement
 
Hi ExcelMonkey,

Maybe I'm misunderstanding your question, but can't you do something like
this:

For X = 1 to 10
If PublicVariableCounter < 30,000 Then
'Call other modules
End If
Next

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


ExcelMonkey wrote:
I have a For Next Loop. I want to publically define a variable that
updates in another module that increments (1,2,3,4,5 etc). In the
loop below I want to be able to test this public variable to see if
it has reached a defined limit (say 35,0000). When it does, I want
to be able to increment the loop to the next X value. I know I can
Exit the loop with "Exit For". But how do I increment it (i.e. what
Next would do) based on my IF value being true without running the
code under the IF statement?

For X = 1 to 10
If PublicVariableCounter = 30,000 Then [increment X to next value]
Call other modules
Next


Thanks




All times are GMT +1. The time now is 06:54 AM.

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