It’s time to create your first Macro. This tutorial walks you through the process of creating and running your first Excel VBA macro. To begin, launch your Visual Basic Editor.
Adding a new Module
- Click Insert on the top of your window.
- Click Module
Module1 will appear in a subfolder titled “Modules” on the left side in what’s called your “Project Explorer.” Access Project Explorer with the keyboard shortcut Ctrl+R.
Creating a Macro
Copy and paste the following code into Module1:
Sub MyFirstMacro() MsgBox("Hello World") End Sub
You just created a Subroutine Procedure called
Running your Macro
There are many ways to run your macro. One way is to press the green “play” arrow near the top of your Visual Basic Editor.
The quickest way to run a macro is by pressing F5 from your Visual Basic Editor.
A third way is to click “Macros” from your Developer Tab.
After this, select “MyFirstMacro” and press “Run.”
Whichever method you choose, your end result will be the same. Running your macro will display the following message box:
It is now time to formally welcome you to the exciting world of VBA. Stick around to discover some of the amazing things you can do with Excel VBA.
If you really want to learn VBA, grab a copy of our Ultimate VBA Training Bundle before reading our next tutorial. We specifically created these cheat sheets to help you get the most out of our upcoming lessons. Together, the set has over 200 practical tips covering the 125 most important topics in Excel VBA. We also stuffed it with 140 helpful macro examples.