then goto next

clozed75

New Member
Joined
Dec 13, 2009
Messages
45
Hi all, sorry for this very soft question..

assume a FOR..NEXT cycle with a nested IF ...THEN.

how can I go from the THEN statement directly to the NEXT (bypassing other lines) ?

is there anything like IF....THEN GOTO NEXT ??
currently I use a label before the next.. any other way?

thanks

Cloe
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Something like:

Say you want to do something within a loop if a condition is met:
Code:
For i = 1 to 100
    If Cells(i,1).Value=100 Then
        'Then do something
    End If
Next i

To exclude:
Code:
For i = 1 to 100
    If [B]Not[/B] Cells(i,1).Value[B]=[/B]100 Then
        'Then do something
    End If
Next i
 
Upvote 0
If you nest your code properly, this might not be required

FOR....
IF condition is TRUE then
don't do anything
ELSE
do all that other stuff
END IF
NEXT...
 
Upvote 0
If you nest your code properly, this might not be required

FOR....
IF condition is TRUE then
don't do anything
ELSE
do all that other stuff
END IF
NEXT...

Weaver, you can eliminate the Else statement as follows:

Code:
If [COLOR=DarkRed][B]Not [/B][/COLOR]condition is True Then
    'do all that other stuff
End If
 
Upvote 0
something like..

For Each cell In Range("xxx")


If xxxx = xxx And yyy= yyy Then
goto fine
else
(code)
end if
(code ..code)

fine:
next
 
Upvote 0
Cloe

GoTo is available but it really should be avoided.

Using it and labels will probably make the code harder to understand and follow rather than the opposite.

There are plenty of other methods you could use, like the IF... that has already been suggested.

It really depends on what the code is meant to do.

As has been asked already, can you post some sample code?.:)
 
Upvote 0
something like..

For Each cell In Range("xxx")


If xxxx = xxx And yyy= yyy Then
goto fine
else
(code)
end if
(code ..code)

fine:
next

Try;

Code:
For Each cell in Range("xxx")
    If [B]Not[/B] (xxx=xxx And yyy=yyy) Then
        (code)
    End If
Next cell
 
Upvote 0

Forum statistics

Threads
1,225,122
Messages
6,182,971
Members
453,142
Latest member
Konstako

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top