How to use the VBA editor in Excel
Before you start coding, you’ll need to open the VBA editor. To do this, head to the Developer tab and click the Visual Basic button:
If you don’t see the Developer tab, go to File > Options > Customize Ribbon and make sure that the developer tab is checked in the right pane. If you want a more thorough explanation of how to add the developer tab in Excel, read it here.
You can also open the VBA editor with the shortcut key Alt + F11.
As you can see, the VBA editor is packed full of buttons, menu bars, and options. Don’t worry—we’ll go through the important ones in this guide.
In this guide, we’ll focus on the most basic parts of the Visual Basic editor.
The project view, in the left, vertical, menu bar in the VBA editor, has a folder called Modules.
This folder holds Excel VBA modules, which are like containers for VBA code. When you record macros, they’re included in a module.
Modules also contain the code window where you’ll be writing code (if you’re not recording it).
To add a new, empty module, click the Insert menu button and select Module.
If there was no Modules folder in VBAProject, the folder will be created and there will be a new module inside of it. This is where you’ll put your Excel VBA code when you’re ready to write it.
To delete a module, right-click it in the left pane and select Remove [module name].
Excel will ask you to confirm the removal. You may export the module if you’d like to save it.
Finally, let’s look at running a macro from the Visual Basic Editor window.
After you’ve created a macro, either by coding it directly or recording it from the standard Excel interface, you can run it from this view.
To run a macro, just click the Run Macro button in the menu bar:
You can also press the shortcut key F5 on your keyboard to run the macro from the VBA editor.