GoTo won't work - why?

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

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.
 
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:
 
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.
 
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)
 
Back
Top