Microsoft KB Archive/70476

{|
 * width="100%"|

Use of GOTO and RUN Macro Commands in Excel

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 5.0
 * Microsoft Excel for OS/2, versions 2.2, 3.0

-

SUMMARY
The GOTO macro function branches from the currently running macro and runs the sequence of macro commands at the line or defined name within the GOTO parameters and does not return. The RUN macro function proceeds to run the macro commands at the location specified within the RUN parameters, and when the =RETURN line is encountered, returns to the macro line immediately following the RUN macro function and finishes running that macro.

MORE INFORMATION
Consider the following examples of the GOTO and RUN functions:

  A1:  =ALERT(&quot;this is the first set&quot;) A2: =GOTO(A6) A3: =ALERT(&quot;this is the first set again&quot;) A4: =RETURN A5: A6: =ALERT(&quot;this is the second set&quot;) A7: =RUN(A11) A8: =ALERT(&quot;welcome back to the second set&quot;) A9: =RETURN A10: A11: =ALERT(&quot;welcome to this third step&quot;) A12: =RETURN

When you run this macro at A1, Microsoft Excel generates an alert message showing &quot;this is the first set.&quot; Then it branches to line A6 and displays the alert message &quot;this is the second set.&quot; Microsoft Excel then jumps to line A11 and displays the alert message &quot;welcome to this third set&quot;. When it encounters the =RETURN command at A12, Microsoft Excel jumps back to A8 and displays the alert message &quot;welcome back to the second set.&quot; When it executes =RETURN at A9, the Microsoft Excel macro program stops and does not go back to A3 and continue.

The GOTO command is a branch command that breaks off running the rest of lines immediately following and executes a separate routine of macros. To return to a macro that broke off as a result of a GOTO command, you need to place another GOTO to return back. This extra step can be eliminated by using the RUN command.

NOTE: This is also true for version 5.0 macro sheets, but not modules.