ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is there a VBA flow control statement that will ... (https://www.excelbanter.com/excel-programming/356427-there-vba-flow-control-statement-will.html)

[email protected]

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

Dave Peterson

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

[email protected]

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.

[email protected]

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.

Dave Peterson

Is there a VBA flow control statement that will ...
 
If that "do lots of things" gets too messy, you could always replace it with a
call to a subroutine or a function.



wrote:

"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.


--

Dave Peterson

[email protected]

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



Dave Peterson

Is there a VBA flow control statement that will ...
 
Not that I know.

wrote:

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


--

Dave Peterson

[email protected]

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.


All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com