Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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



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
nested IF statements ssimer Excel Worksheet Functions 3 August 22nd 08 12:47 AM
nested if statements Teethless mama Excel Worksheet Functions 0 March 28th 07 12:23 AM
Nested if statements - is there a better way? masterbaker Excel Worksheet Functions 3 July 25th 06 04:59 PM
Nested If Statements Jasmine Excel Worksheet Functions 2 January 26th 06 03:47 PM
Nested If/Then statements qwik6 Excel Worksheet Functions 3 December 9th 05 03:38 AM


All times are GMT +1. The time now is 05:08 PM.

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

About Us

"It's about Microsoft Excel"