ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Jumping out of loop with GoTo function (https://www.excelbanter.com/excel-programming/373860-jumping-out-loop-goto-function.html)

Andy

Jumping out of loop with GoTo function
 
Hi people!

I would like to jump out of a Do loop using the goto statement e.g.

Do Until condition

While i= 0 And i < value

if value = 1

GoTo Line1:

End If

Wend

Loop

Line1:

Obviously this doesn't do anything, but is the structure correct and
the code correct for the statements shown? Do I need to declare Dim
Line1 as String. My program doesn't work and I think GoTo has something
to do with it not working. I do not have the help file either.

Thank you


Die_Another_Day

Jumping out of loop with GoTo function
 
If value = 1 Then 'Forgot the "Then"
GoTo Line1 'No colon needed here

HTH

Charles

Andy wrote:
Hi people!

I would like to jump out of a Do loop using the goto statement e.g.

Do Until condition

While i= 0 And i < value

if value = 1

GoTo Line1:

End If

Wend

Loop

Line1:

Obviously this doesn't do anything, but is the structure correct and
the code correct for the statements shown? Do I need to declare Dim
Line1 as String. My program doesn't work and I think GoTo has something
to do with it not working. I do not have the help file either.

Thank you



LenB

Jumping out of loop with GoTo function
 
Hi Andy
If Line1: would be the next statement after Loop, you can use

....
if value = 1 then
Exit Do
End If
Wend
Loop
'goes here if value = 1
.....

Avoid using Goto whenever possible, which is almost always. The only
place it is still needed is "On Error Goto...."

Len

Andy wrote:
Hi people!

I would like to jump out of a Do loop using the goto statement e.g.

Do Until condition

While i= 0 And i < value

if value = 1

GoTo Line1:

End If

Wend

Loop

Line1:

Obviously this doesn't do anything, but is the structure correct and
the code correct for the statements shown? Do I need to declare Dim
Line1 as String. My program doesn't work and I think GoTo has something
to do with it not working. I do not have the help file either.

Thank you



All times are GMT +1. The time now is 12:31 PM.

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