ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GoTo won't work - why? (https://www.excelbanter.com/excel-programming/424802-goto-wont-work-why.html)

Jim[_7_]

GoTo won't work - why?
 
In a sub

TryAgain:

(some code)

Application.GoTo TryAgain

(more code)

End Sub

I never use GoTo statements except for error handling so I wonder if they
will backup as well as skipping lines? I really need this thing to back up.
When running, the Application.Goto TryAgain line is skipped as if it isn't
there. Not even an error. What's up?

Thanks for any help.



JLGWhiz

GoTo won't work - why?
 
It will not stop at the label, but should execute the first line after the
label.

TryAgain:

MsgBox "This line executes
'More code
Application.GoTo TryAgain:


"Jim" wrote:

In a sub

TryAgain:

(some code)

Application.GoTo TryAgain

(more code)

End Sub

I never use GoTo statements except for error handling so I wonder if they
will backup as well as skipping lines? I really need this thing to back up.
When running, the Application.Goto TryAgain line is skipped as if it isn't
there. Not even an error. What's up?

Thanks for any help.




Jim[_7_]

GoTo won't work - why?
 
I fixed it. I changed Application.Goto TryAgain to just Goto TryAgain but
this didn't work either. I closed Excel and restarted it. Now it works.

"Jim" wrote in message
...
In a sub

TryAgain:

(some code)

Application.GoTo TryAgain

(more code)

End Sub

I never use GoTo statements except for error handling so I wonder if they
will backup as well as skipping lines? I really need this thing to back
up. When running, the Application.Goto TryAgain line is skipped as if it
isn't there. Not even an error. What's up?

Thanks for any help.




Chip Pearson

GoTo won't work - why?
 

I fixed it. I changed Application.Goto TryAgain to just Goto TryAgain


Goto and Application.Goto are completely unrelated. Application.Goto
scrolls to and display a location on a worksheet. VBA's GoTo moves the
execution point in code.

Just as an aside, I would try to eliminate the need for a Goto
statement and make your code more structured and modular. Goto is
universally considered a very poor coding practice by professional
developers. One or two Gotos may be harmless, but code with lots of
Goto jumps make debugging, maintenance, and expansion quite difficult.
You don't want to get in the habit of using Gotos. They are bad news.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sat, 28 Feb 2009 22:43:45 -0600, "Jim"
wrote:

I fixed it. I changed Application.Goto TryAgain to just Goto TryAgain but
this didn't work either. I closed Excel and restarted it. Now it works.

"Jim" wrote in message
.. .
In a sub

TryAgain:

(some code)

Application.GoTo TryAgain

(more code)

End Sub

I never use GoTo statements except for error handling so I wonder if they
will backup as well as skipping lines? I really need this thing to back
up. When running, the Application.Goto TryAgain line is skipped as if it
isn't there. Not even an error. What's up?

Thanks for any help.




All times are GMT +1. The time now is 06:40 PM.

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