E.g. Given Sheet 1 contains:
Ref: Do things
How can I direct a code in Module 1 to GoTo Ref
? If I were in the Sheet1
code moduke then I could simply use a
Goto Ref
But this doesn't work across different modules
E.g. Given Sheet 1 contains:
Ref: Do things
How can I direct a code in Module 1 to GoTo Ref
? If I were in the Sheet1
code moduke then I could simply use a
Goto Ref
But this doesn't work across different modules
Your question is not clear and you didn't provide any code, so this is a guess.
GoTo is used to jump to different locations within the same sub/function. You cannot use it to jump to parts of other sub routines or functions, which it sounds like you might be trying to do.
Also, "NapDone:" is not called a reference, it's formally called a line label. :)
To help expand on the other answers.. Like they said you shouldn't use GoTo for anything in VBA except error handling.
What you should be doing is calling a public sub/function from another module. For example in Module 1 you would have the following
and on Module 2 you have
So now you know how to avoid it. GoTo is not very good programming practice as you'll have things flying all over the place. Try to break down code you're repeating into multiple Subs and just call them when needed, or functions whatever be the case. Then you'll get into classes, which are just wrapped up to represent an object and it'll do all the work for that object.
This should get you on the right track.