Adding a Module | Creating a Macro | Running a Macro

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

  1. Click Insert on the top of your window.
  2. Click Module Insert 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 MyFirstMacro.

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.
VBA run macro

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.
VBA Macros Button

After this, select “MyFirstMacro” and press “Run.”
VBA run macro

Whichever method you choose, your end result will be the same. Running your macro will display the following message box:
VBA Hello World

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.