Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Skip to Next "x" inside of a For Next Loop

Hello

In a large For Next loop, I have many criteria. If any one of these
criteria is a certain value I want to immediately go to the Next x. How can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go immediately to the Next x
without considering Criteria 3 and 4.

I cannot figure out how to advance the Next x.

Thank you.

W


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Skip to Next "x" inside of a For Next Loop


"verizon" ha scritto nel messaggio
...
Hello

In a large For Next loop, I have many criteria. If any one of these
criteria is a certain value I want to immediately go to the Next x. How

can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go immediately to the Next x
without considering Criteria 3 and 4.

I cannot figure out how to advance the Next x.


For x = 1 To 100
'...
If Not (criterion1) Then
If Not (criterion2) Then
If Not (criterion3) Then
If Not (criterion4) Then
'...
End If
End If
End If
End If

'....
Next

---------------

OR

---------------

For x = 1 To 100
'...
If criterion1 Then GoTo ciao
If criterion2 Then GoTo ciao
If criterion3 Then GoTo ciao
If criterion4 Then GoTo ciao
'...
ciao:
Next


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default Skip to Next "x" inside of a For Next Loop

Doesn't an If/ElseIf or Select Case construct do this?
Both constructs end as soon as a true condition is found.

Example 1:
For x = 1 To 100
If Criteria 1 Then
'Do something
ElseIf Criteria 2 Then
'Do something
ElseIf Criteria 3 Then
'Do something
ElseIf Criteria 4 Then
'Do something
End If
Next

Example 2:
For x = 1 To 100
Select Case ActiveCell.Value
Case Is = Value1
'Do something
Case Is = Value2
'Do something
Case Is = Value3
'Do something
Case Is = Value4
'Do something
End Select
Next

Regards,
Greg

-----Original Message-----
Hello

In a large For Next loop, I have many criteria. If any

one of these
criteria is a certain value I want to immediately go to

the Next x. How can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go

immediately to the Next x
without considering Criteria 3 and 4.

I cannot figure out how to advance the Next x.

Thank you.

W


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Skip to Next "x" inside of a For Next Loop

verizon

A couple of ways


For x = 1 To 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4

If Criterion1 = False Then
'your code here
ElseIf Criterion2 = False Then
'your code here
ElseIf Criterion3 = False Then
'your code here
ElseIf Criterion4 = True Then
'your code here
ElseIf Criterion4 = False And Criterion3 = True Then
'your code here
End If
Next x




or




For x = 1 To 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4

If Criterion1 = True Then
GoTo JumpHere
End If
'your code here
JumpHe
Next

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Skip to Next "x" inside of a For Next Loop

In a large For Next loop, I have many criteria. If any one of these
criteria is a certain value I want to immediately go to the Next x. How can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go immediately to the Next x
without considering Criteria 3 and 4.


try this:

Sub MyLoop()
Dim x As Integer
Dim Criterion1 As Boolean
Dim Criterion2 As Boolean
Dim Criterion3 As Boolean
Dim Criterion4 As Boolean

'Criterion2 = True

For x = 1 To 100
Select Case True
Case Criterion1, Criterion2, Criterion3, Criterion4
MsgBox "someone is true"
End Select
Next x
End Sub

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Skip to Next "x" inside of a For Next Loop

If, say, Criterion 2 is true, I would like to go immediately to the Next x
without considering Criteria 3 and 4.


try this:

Sub MyLoop()
Dim x As Integer
Dim Criterion1 As Boolean
Dim Criterion2 As Boolean
Dim Criterion3 As Boolean
Dim Criterion4 As Boolean

'Criterion2 = True

For x = 1 To 100
Select Case True
Case Criterion1, Criterion2, Criterion3, Criterion4
MsgBox "someone is true"
End Select
Next x
End Sub



Supplement, if no variable is true:

Select Case True
Case Criterion1, Criterion2, Criterion3, Criterion4
MsgBox "someone is true"
Case Else
MsgBox "nothing is true"
End Select

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default Skip to Next "x" inside of a For Next Loop

Hi,



For x = 1 to 100
Criterion 1
Criterion 2
if criteria 2 i= true then goto nextxline 'in on word, it is just a
label
Criterion 3
Criterion 4
nextxline :
Next x
Regards,

Jean-Yves



"verizon" wrote in message
...
Hello

In a large For Next loop, I have many criteria. If any one of these
criteria is a certain value I want to immediately go to the Next x. How

can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go immediately to the Next x
without considering Criteria 3 and 4.

I cannot figure out how to advance the Next x.

Thank you.

W




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Skip to Next "x" inside of a For Next Loop

This is a missing function in VB. In C++ you'd put "continue;" to restart
the loop at the next iteration. In VB this is most often done with a
If/Then/Else construct within the loop (many people have demonstrated this)
or you can "cheat" and use a GoTo, but that practice is frowned upon by most
VB programmers.

--
JT Lovell

"verizon" wrote in message
...
Hello

In a large For Next loop, I have many criteria. If any one of these
criteria is a certain value I want to immediately go to the Next x. How

can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go immediately to the Next x
without considering Criteria 3 and 4.

I cannot figure out how to advance the Next x.

Thank you.

W




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Skip to Next "x" inside of a For Next Loop

i think you could be right. will try.

Thx

W
"Greg Wilson" wrote in message
...
Doesn't an If/ElseIf or Select Case construct do this?
Both constructs end as soon as a true condition is found.

Example 1:
For x = 1 To 100
If Criteria 1 Then
'Do something
ElseIf Criteria 2 Then
'Do something
ElseIf Criteria 3 Then
'Do something
ElseIf Criteria 4 Then
'Do something
End If
Next

Example 2:
For x = 1 To 100
Select Case ActiveCell.Value
Case Is = Value1
'Do something
Case Is = Value2
'Do something
Case Is = Value3
'Do something
Case Is = Value4
'Do something
End Select
Next

Regards,
Greg

-----Original Message-----
Hello

In a large For Next loop, I have many criteria. If any

one of these
criteria is a certain value I want to immediately go to

the Next x. How can
I do that:

For x = 1 to 100
Criterion 1
Criterion 2
Criterion 3
Criterion 4
Next x

If, say, Criterion 2 is true, I would like to go

immediately to the Next x
without considering Criteria 3 and 4.

I cannot figure out how to advance the Next x.

Thank you.

W


.



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Skip to Next "x" inside of a For Next Loop

You could also try:

For x = 1 to 100
criteria 1
criteria 2
if criteria 2 = true then goto NextX
criteria 3

NextX:
Next x

This way, the script will run normally, and if criteria2 is true i
will skip criteria 3 (and further script) and go immediately to th
Next x statement

--
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
why does my "TAB" key skip a column in excel spread sheets? luke01 Excel Worksheet Functions 2 January 18th 08 02:04 PM
Question on "On Error GoTo skip" dan Excel Discussion (Misc queries) 2 July 1st 07 10:48 PM
How do I run a macro from inside an"=IF" formula in Excel 2003? Drawn83 Excel Worksheet Functions 1 June 4th 07 08:38 PM
skip checkbox to next tab with "enter" Jared New Users to Excel 0 October 24th 06 04:57 AM


All times are GMT +1. The time now is 02:20 AM.

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

About Us

"It's about Microsoft Excel"