Use of GOTO and RUN Macro Commands in Excel

ID: Q70476


The information in this article applies to:


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("this is the first set")
   A2:  =GOTO(A6)
   A3:  =ALERT("this is the first set again")
   A4:  =RETURN()
   A5:
   A6:  =ALERT("this is the second set")
   A7:  =RUN(A11)
   A8:  =ALERT("welcome back to the second set")
   A9:  =RETURN()
   A10:
   A11: =ALERT("welcome to this third step")
   A12: =RETURN() 


When you run this macro at A1, Microsoft Excel generates an alert message showing "this is the first set." Then it branches to line A6 and displays the alert message "this is the second set." Microsoft Excel then jumps to line A11 and displays the alert message "welcome to this third set". When it encounters the =RETURN() command at A12, Microsoft Excel jumps back to A8 and displays the alert message "welcome back to the second set." 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.


REFERENCES

"Online Help," version 5.0
"Function Reference," version 4.0, pages 213-214, 367-368
"Function Reference," version 3.0, pages 118-119, 202-203
"Functions and Macros," version 2.1x, pages 303, 345

Additional query words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.0 4.0 5.0


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 23, 1999