How to use GoTo Statement in Microsoft Excel VBA

Suppose you have a worksheet that contains a list of orders, along with the order date, customer name, and order total. You want to write a VBA macro that will find all the orders that were placed before February 20, 2023 & and highlight them in red.

Follow the below steps to accomplish this.

The “GoTo” statement in VBA (Visual Basic for Applications) is used to jump to a specific line of code within a VBA module. In Microsoft Excel, you can use the “GoTo” statement to jump to a specific cell or range on a worksheet.

Step 1 – Open VBA Editor

– Open VBA editor by pressing ALT + F11 key or under Developer Tab in the code section click Visual Basic.

Step 2 – Microsoft VBA Editor Screen

– When you click on the visual basic button, Microsoft VBA editor screen will open. Here we will type our GoTo statement.

Step 3 – Type Your Code With GoTo Statement

– Type the following code.

Step 4 – Save Your Worksheet

– When you finish typing the code, press CTRL + S or save button. Save As dialogue box will appear on your screen. Give your file a name, select destination & select file type as “Excel Macro-Enabled Workbook” from drop down list and press save button.

Step 5 – Open Macro Screen

– Under Developer Tab in the code section click the Macros button to open Macro screen or press ALT + F8 key.

Step 6 – Run The Macro

– When you click on the Macros button, a screen with Macro will appear on your screen. Select Macro & press Run button to execute the Macro.

Step 7 – Orders Highlighted

– Once you click the Run, Macro will be executed & your order before February 20, 2023 will be highlighted.