ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Breaking Out of an If Statement (https://www.excelbanter.com/excel-programming/298744-breaking-out-if-statement.html)

scain2004[_11_]

Breaking Out of an If Statement
 
I have an IF statement within a For Next loop.

How can I break out of an IF statement and move on to the next loo
iteration

--
Message posted from http://www.ExcelForum.com


Harlan Grove[_5_]

Breaking Out of an If Statement
 
"scain2004 <" wrote...
I have an IF statement within a For Next loop.

How can I break out of an IF statement and move on to the next loop
iteration?


You could use GoTo, but it's likely there's a better way. If you post your code,
someone here is likely to be able to suggest such a better way.

--
To top-post is human, to bottom-post and snip is sublime.

Tom Ogilvy

Breaking Out of an If Statement
 
In general, this appears to be a design issue. You didn't say nested if
statements, so the general approach:
for i = 1 to 10
if condition then
' code to execute if condition is met
end if
Next

--
Regards,
Tom Ogilvy

"scain2004 " wrote in message
...
I have an IF statement within a For Next loop.

How can I break out of an IF statement and move on to the next loop
iteration?


---
Message posted from http://www.ExcelForum.com/




scain2004[_12_]

Breaking Out of an If Statement
 
It goes like this:

For i = 0 To counter

...some code...

If

For j = 0 To ....
If
...some code
....break out to Next i
ElseIf
...some code
...break out to Next i
ElseIf
...some code
End If
Next j

ElseIf

For j = 0 To ....
If
...some code
....break out to Next i
ElseIf
...some code
...break out to Next i
ElseIf
...some code
End If
Next j

End If

Next

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Breaking Out of an If Statement
 
where you want to break out

exit for





--
Regards,
Tom Ogilvy


"scain2004 " wrote in message
...
It goes like this:

For i = 0 To counter

..some code...

If

For j = 0 To ....
If
..some code
...break out to Next i
ElseIf
..some code
..break out to Next i
ElseIf
..some code
End If
Next j

ElseIf

For j = 0 To ....
If
..some code
...break out to Next i
ElseIf
..some code
..break out to Next i
ElseIf
..some code
End If
Next j

End If

Next i


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:28 PM.

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