![]() |
Jumping Out of Nested Statements
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 |
Jumping Out of Nested Statements
Sub test() For Each cell In ActiveSheet.Range("a1:a50") cell.Select If cell.Row = 5 Then Exit For Next cell End Sub -----Original Message----- 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 . |
Jumping Out of Nested Statements
In your example, a straight Exit For should work.
-- HTH RP (remove nothere from the email address if mailing direct) "Stratuser" wrote in message ... 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 |
Jumping Out of Nested Statements
I don't want to exit the For loop, I just want to go to the next item in the
range. "Stratuser" wrote: 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 |
Jumping Out of Nested Statements
use a label
For each x in range if x then .. if y then goto loopNext .. end if loopNext: next keepITcool < email : keepitcool chello nl (with @ and .) < homepage: http://members.chello.nl/keepitcool ?B?U3RyYXR1c2Vy?= wrote : I don't want to exit the For loop, I just want to go to the next item in the range. "Stratuser" wrote: 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 |
Jumping Out of Nested Statements
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. "Stratuser" wrote in message ... 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 |
All times are GMT +1. The time now is 03:36 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com