Changing the flow using the GoTo statement
In this recipe, we will be exploring the GoTo
statement. Before I say another word, it is important to mention that whatever we do in this recipe is nothing more than a basic explanation of how to use the GoTo
statement. The only time you should ever use it is when you do error handling, which will be discussed in Chapter 11, Handling Errors. The Sub procedure we create here is, however, a good example of how you can control program flow.
Let's see how the GoTo
statement works.
Getting ready
Open Excel and activate a new workbook. Save the file as a macro-enabled file on your desktop and call it ProgramFlow
. Sheet1 should be active. Press Alt + F11 to switch to the VBA Editor. With that open, insert a new module.
How to do it…
- Create a new Sub procedure and call it
GoToSample
:Sub GotoSample() End Sub
- Add the following lines of code:
Sub GotoSample() Password = InputBox("Enter...