From: Luke on 19 Feb 2010 15:16 I have a for-next loop, within which I want to check to see if a certain condition is true. If it is true, I want to skip the rest that particular iteration and move on to the next one in the loop. I tried code that looked like the following, but it just gave me a "next without for" error: For x = 1 to 11 If condition = true then next x End if Next x I want to do this without using a GoTo statement. Any suggestions?
From: Paul C on 19 Feb 2010 15:29 There is no built in "Skip to next" function the only loop command available is Exit For, which is not what you want. A Goto is really the best option, but if you really do not want to use one you can use an additional single loop with an Exit For like this. For x = 1 To 11 For A = 1 To 1 'Condition Check If Condition = True Then Exit For 'Do more stuff here if Condition=false Next A Next x -- If this helps, please remember to click yes. "Luke" wrote: > I have a for-next loop, within which I want to check to see if a certain > condition is true. If it is true, I want to skip the rest that particular > iteration and move on to the next one in the loop. I tried code that looked > like the following, but it just gave me a "next without for" error: > > For x = 1 to 11 > If condition = true then > next x > End if > Next x > > I want to do this without using a GoTo statement. Any suggestions?
From: Ryan H on 19 Feb 2010 15:32 Change the If...Then statement to False. If its, True it will go to the next x. Hope this helps! If so, let me know, click "YES" below. For x = 1 to 11 If condition = False then next x End if Next x -- Cheers, Ryan "Luke" wrote: > I have a for-next loop, within which I want to check to see if a certain > condition is true. If it is true, I want to skip the rest that particular > iteration and move on to the next one in the loop. I tried code that looked > like the following, but it just gave me a "next without for" error: > > For x = 1 to 11 > If condition = true then > next x > End if > Next x > > I want to do this without using a GoTo statement. Any suggestions?
From: Luke on 19 Feb 2010 15:36 Thanks. I'm not against GoTo's as such, but would rather not use them if possible. But you're right - it does appear to be the best option in this case. "Paul C" wrote: > There is no built in "Skip to next" function the only loop command available > is Exit For, which is not what you want. > > A Goto is really the best option, but if you really do not want to use one > you can use an additional single loop with an Exit For like this. > > For x = 1 To 11 > For A = 1 To 1 > 'Condition Check > If Condition = True Then Exit For > 'Do more stuff here if Condition=false > Next A > Next x > > > -- > If this helps, please remember to click yes. > > > "Luke" wrote: > > > I have a for-next loop, within which I want to check to see if a certain > > condition is true. If it is true, I want to skip the rest that particular > > iteration and move on to the next one in the loop. I tried code that looked > > like the following, but it just gave me a "next without for" error: > > > > For x = 1 to 11 > > If condition = true then > > next x > > End if > > Next x > > > > I want to do this without using a GoTo statement. Any suggestions?
From: Ryan H on 19 Feb 2010 15:38 Correction. For x = 1 to 11 If condition = False then ' do something End if Next x -- Cheers, Ryan "Luke" wrote: > I have a for-next loop, within which I want to check to see if a certain > condition is true. If it is true, I want to skip the rest that particular > iteration and move on to the next one in the loop. I tried code that looked > like the following, but it just gave me a "next without for" error: > > For x = 1 to 11 > If condition = true then > next x > End if > Next x > > I want to do this without using a GoTo statement. Any suggestions?
|
Next
|
Last
Pages: 1 2 Prev: If And formular Or somthing else Next: Excel AddIn - how to get formula from Formula Dialog |