Goto

Syntax

Goto Label

Remarks

Redirects a running macro from the Goto instruction to the specified Label anywhere in the same subroutine or function. The macro continues running from the instruction that follows the label. Keep the following in mind when placing a label in a macro:

Example

This macro displays a message box, with Yes, No, and Cancel buttons, asking if the user wants to continue the macro. If the user chooses No or Cancel, the macro branches to the label bye immediately before End Sub, and the macro ends.


Sub MAIN
ans = MsgBox("Continue macro?", 3)
If ans = 0 Or ans = 1 Then Goto bye
'Series of instructions to run if the user chooses Yes
bye:
End Sub

See Also

For¼Next, If¼Then¼Else, Select Case, While¼Wend