Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Excel how to get back to the code after using the GoTo statement? 1

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
This may sound like a very simple question. But does anyone know how to get back to the point where you were after completing a GoTo statement (In REXX it is call, then return after the call is complete).
Any advice would be much apprecuiated.
Thanks,
Knifey.
 
I suggest you use GoSub and Return. Go To is almost never necessary and is pretty universally frowned on in programming communities. If you insist, you'd have to set a Go To again in the gone to code to get back to where you started.

_________________
Bob Rashkin
 
Simple, don't use GoTo (except for error handling)

Use Call:
Code:
Line1
Call MySub
Line2

Private Sub MySub()

End Sub

So after Call MySub you will get back to Line2 of your code. Automagically :)


Have fun.

---- Andy
 




Hi,

Results in, what is referred to as, spaghetti code.

Skip,

[glasses] When a wee mystic is on the loose..
It's a Small Medium at Large! [tongue]
 
Thanks everyone,
This works like a dream.
Skip, I know this creates spaghetti code but I have around 15 different scenarios that point to the same code. So it was either this or replicate the code 15 times.
Cheers,
Roy
 




Well designed GoSub/Return, is not spaghetti code.

Skip,

[glasses] When a wee mystic is on the loose..
It's a Small Medium at Large! [tongue]
 
Thanks for the help everyone,
I went with the gosub and return which has worked out perfectly (thanks Bob).
Cheers,
Roy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top