Article ID: 213486 - Last Review: June 11, 2007 - Revision: 3.6 XL2000: Branching to Other Sections of Code with GoTo and CallThis article was previously published under Q213486 On This PageSUMMARY
In Microsoft Excel versions 5.0 and later, you can use the GoTo and Call statements to branch to other sections of a Microsoft Visual Basic for Applications procedure.
NOTE: In earlier versions of Excel, you can do this with the GOTO() and RUN() functions. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites: Microsoft Certified Partners - https://partner.microsoft.com/global/30000104 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (http://support.microsoft.com/gp/advisoryservice) For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) GoToThe GoTo statement jumps to and runs the instructions at the specific line label and continues running them until the end of the program is reached.CallThe Call statement runs a procedure and then returns to the line immediately after the Call statement in the originating procedure. The Call statement can also pass arguments of any declared data type to the called procedure and can transfer control to a Sub procedure, Function procedure, dynamic-link library (DLL) procedure, or Macintosh code resource procedure.The following examples demonstrate how to use GoTo and Call. Example 1: The Difference Between Call and GoToThe following Visual Basic procedure demonstrates the difference between using the GoTo statement and the Call statement:Example 2: An Alternative to the Call StatementThe following Visual Basic code makes a call to a another Sub procedure without using the Call statement:Example 3: Using GoTo for Conditional BranchingThe following code shows how you can combine the If...Then...Else statement with the GoTo statement to provide more branching options or to create the ability to return to a specific location after the GoTo statement is run:
| Article Translations
|
Back to the top
