This VBA tutorial will teach you the basics of using VBA with Excel. No prior coding experience? Don’t worry! Because VBA interacts directly with Excel, coding is very intuitive. Beginners can learn VBA very quickly!
You can create a free account to save your progress by clicking the Create an Account button above. Once you’re signed up, your progress will be saved whenever you leave the app. When you return, you will be prompted to continue where you left off.
You can click "Start the Course" to get started, review the Course Contents below, or below the Course Contents you will find an introductory tutorial covering What is VBA, the Visual Basic Editor, Recording Macros, and more.
Now let's get started:
Note: Creating an account allows you to save your progress. When you reopen this app you will be able to return to the next unanswered question.
VBA stands for Visual Basic for Applications - an implementation of Microsoft’s Visual Basic language built into most Microsoft Office applications (in our case, Microsoft Excel). You can program VBA to complete any task that you could manually do while working in Excel or other applications. By using VBA code you can automate repetitive tasks saving valuable time and energy. You can learn more about the background of VBA on Wikipedia.
The Visual Basic Editor is where VBA code is stored:
You can access the Visual Basic Editor in the Developer Ribbon:
or with the shortcut ALT + F11.
If you don’t see the Developer Ribbon, you will need to add it (directions in the next section).
In the Visual Basic Editor you will find the Project Window. This window contains a list of the “modules” for all open workbooks. Modules are where the code is stored. There are three module types:
To insert a module, go to the Insert Menu (ALT > I).
You can (and should) rename Modules in the Properties Window. Renaming modules makes it easier to organize your code. If your VBA project contains more than one module, you should rename the modules.
By default, the Developer Ribbon is not visible. You will need to manually turn it on. Follow these steps to enable the Developer Ribbon:
The Macro Recorder allows you to “record” your actions to VBA code. Even if you don’t know one bit of VBA code, you can use the Macro Recorder to create VBA procedures that repeat a series of actions.
Recording a Macro is easy:
When Recording a Macro there are two options: ‘Use Relative References’ or not.
This setting changes how your code is recorded when selecting different cells. With ‘Use Relative References’ turned off, the Macro Recorder will record the actual cell ranges that you select. With it turned on, when using the keyboard to navigate, the Macro Recorder will record "offsets" from the activecell. Here is an example: Suppose you start in cell A1 and press the right arrow. With ‘Use Relative References’ turned off, cell B1 is recorded. With it turned on, Activecell.Offset(1,0) is recorded instead. This makes your code flexible based on whatever cell is selected when you run the Macro:
To run a macro, navigate to the Developer Ribbon and select Macros:
Then select your desired Macro and click Run:
Notice from this menu you can also select "Edit". Edit will open the code for that macro within the Visual Basic Editor.
AutoMacro is a VBA add-in that makes coding easier for everyone:
Simply select a code fragment from the AutoMacro menus and it will insert directly into the active module. AutoMacro contains finished procedures, and also smaller code fragments, allowing anyone to code VBA procedures from scratch. AutoMacro also contains many time saving features designed with experienced coders in mind.
After going through the tutorial check out our VBA Code Examples