VBA - GoTo Statements

GoTo statements allow for the flow of the code to jump to set label in the code.

Here is a basic example showing how a label is created and how a GoTo statement can be used to jump through the code.

It is worth noting that GoTo statements are useful though they can have a negative effect on the readability of the code. Jumping between points of the program makes it difficult to determine what value variables are assigned. GoTo statements are not necessary  and can be avoided - many programming languages do not allow GoTo statements for this reason.

Labels are also used in error handling.

Code Snippet:

Sub a16_goto()

GoTo end2

MsgBox "Hello"


End Sub

Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.

Must Read Articles

VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.
Installing VBA and First Program - What do you need to start using visual basic application VBA.