Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default 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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Breaking into Workbook_Open Bob Barnes Excel Discussion (Misc queries) 2 July 29th 09 10:45 PM
Breaking links Jessica Excel Worksheet Functions 1 June 12th 08 11:56 PM
breaking during a macro run maxzsim Excel Discussion (Misc queries) 1 March 9th 06 07:51 AM
Breaking Links thelees Excel Discussion (Misc queries) 1 September 24th 05 07:11 PM
breaking out of a loop ChuckM[_2_] Excel Programming 1 December 16th 03 07:07 PM


All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"