Jumping Out of Nested Statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a block containing several levels of nested statements within a For
Each...Next loop. I'm using a GoTo statement to make execution jump to the
end of the loop. It works, but I'm wondering if there isn't a better way to
do this, because I've read that you should not use line numbers to jump
around inside a subroutine. Any ideas? Here's the structure of the code:

For Each X in Range("TickerList")
If ....
With .....
Select Case True
Case ...

Case ...
If ....
GoTo 15 'from here i want to jump
to Next X
End If
End Select
End With
End If
Next X
 
Sub test()

For Each cell In ActiveSheet.Range("a1:a50")

cell.Select
If cell.Row = 5 Then Exit For

Next cell

End Sub
 
In your example, a straight Exit For should work.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Why do you need to jump at all?

VB "select case" clauses are mutually exclusive and you can structure your
if.. then so that the Goto is not required.

Tim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top