Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Is there a VBA flow control statement that will ...

Is there a VBA statement that will caus a loop to immediately do the next
iteration? For example:

sub x()
.....
For i=strt To stp
if not isnumeric(cells(i,j)) then goto Lbl
...
...
Lbl:
Next i

I would like to avoid the goto and say:
if not isnumeric(cells(i,j)) then NextIteration

Thanks for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Is there a VBA flow control statement that will ...

Why not just use your if/then/else statement.

For i=strt To stp
if not isnumeric(cells(i,j)) then
'do nothing
else
'do lots of things
end if
next i



wrote:

Is there a VBA statement that will caus a loop to immediately do the next
iteration? For example:

sub x()
.....
For i=strt To stp
if not isnumeric(cells(i,j)) then goto Lbl
...
...
Lbl:
Next i

I would like to avoid the goto and say:
if not isnumeric(cells(i,j)) then NextIteration

Thanks for any help


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 418
Default Is there a VBA flow control statement that will ...

"Dave Peterson" wrote:
Why not just use your if/then/else statement.
For i=strt To stp
if not isnumeric(cells(i,j)) then
'do nothing
else
'do lots of things
end if
next i


Because Real Programs can sometimes (often!) get unduly
messy with nested "if" statements if you are limited to a
goto-less programming style. Even Dijkstra admitted this
in a public retraction of his (in)famous "GoTos Are Dangerous"
diatribe. To encourage "acceptable" use of "goto",
designers of modern programming languages added
"structured gotos" like "continue" and "break" to go to the
end of a loop or to exit a loop respectively. They also
provide "return" to exit a function in the middle.

I am not very familiar with VBA. VBA does appear to have
Exit For, Exit Do, Exit Function and Exit Sub. But I do not
see any structured statement for continuing a loop from
the middle, other that goto a label at the end of the loop.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 418
Default Is there a VBA flow control statement that will ...

I wrote:
I am not very familiar with VBA. VBA does appear to have
Exit For, Exit Do, Exit Function and Exit Sub. But I do not
see any structured statement for continuing a loop from
the middle, other that goto a label at the end of the loop.


I meant to add that I am surprised that "if ... then next" or
"if ... then next i" does not function as "continue" because
I thought that the specification of some forms of the BASIC
language does, in fact, permit that. Admittedly, it has been
many years (decades!) since I was involved with the
BASIC language for other platforms. So my recollection
could be wrong.
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Is there a VBA flow control statement that will ...

I would like to avoid the complexity of deelpy nested ifs that is sometimes
required. A jump directly to the end of the loop (without using a label)
would be preferred. Many languages have such a statement (such as c's
break statement). I am simply asking if VBA does.

On Sat, 18 Mar 2006 18:25:40 -0600, Dave Peterson
wrote:

Why not just use your if/then/else statement.

For i=strt To stp
if not isnumeric(cells(i,j)) then
'do nothing
else
'do lots of things
end if
next i



wrote:

Is there a VBA statement that will caus a loop to immediately do the next
iteration? For example:

sub x()
.....
For i=strt To stp
if not isnumeric(cells(i,j)) then goto Lbl
...
...
Lbl:
Next i

I would like to avoid the goto and say:
if not isnumeric(cells(i,j)) then NextIteration

Thanks for any help


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Is there a VBA flow control statement that will ...

Thanks for the replies. As others pointed out, there are several ways to
accomplish the same thing, there just not as neat.
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
Macro for Cash flow Statement Kumar Excel Discussion (Misc queries) 0 April 17th 09 05:24 PM
How to create a macro to control data flow JW_4222 Excel Discussion (Misc queries) 1 March 28th 08 02:33 PM
set up a statement of cash flow template for operation activities pheonix Excel Worksheet Functions 0 May 24th 07 07:32 PM
Flow of control from UserForm to Sheet1 sub excelnut1954 Excel Programming 1 December 16th 05 10:08 PM
Flow of control in VBA Question - Userform Interaction Alan Excel Programming 3 December 23rd 04 01:12 PM


All times are GMT +1. The time now is 06:22 AM.

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

About Us

"It's about Microsoft Excel"