Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
nested IF statements | Excel Worksheet Functions | |||
nested if statements | Excel Worksheet Functions | |||
Nested if statements - is there a better way? | Excel Worksheet Functions | |||
Nested If Statements | Excel Worksheet Functions | |||
Nested If/Then statements | Excel Worksheet Functions |