Learn VBA for Excel - Tutorial for Beginners

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:

VBA How To

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.

What is VBA?

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

The Visual Basic Editor is where VBA code is stored:

What is VBA?

You can access the Visual Basic Editor in the Developer Ribbon:

VBA Editor - Tutorial for Excel

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:

Learn VBA Editor Modules in Excel

  • Standard Module:
    • Generic - Most of your code will go in the Modules folder. Unless you have a good reason to put it elsewhere, place your code here.
    • ThisWorkbook - Store workbook-level code. Typically use this for workbook “events” that trigger code to run (workbook open, save, etc.)
    • Sheet-level - Store sheet-level code. Typically use this for worksheet “events” that trigger code to run (worksheet change, worksheet activate, etc.)
  • Form Module - Form Modules store code for UserForms.
  • Class Module - The Class Modules are for advanced VBA programmers. They involve Object Oriented Programming. We will not cover Class Modules in this tutorial.

To insert a module, go to the Insert Menu (ALT > I).

Insert Module in Visual Basic Editor

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.

Rename Module with VBE Properties Window

Add the Developer Ribbon

By default, the Developer Ribbon is not visible. You will need to manually turn it on. Follow these steps to enable the Developer Ribbon:

  • Click File
    Enable Visual Basic Editor - Developer - File
  • Click Options
    Enable Visual Basic Editor - Developer - Options
  • Click Customize Ribbon, Click “Developer” and click OK
    Enable Visual Basic Editor - Developer - enable

Record a Macro

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:

  • Go to Developer > Record a Macro
    Record Macro in VBA for Excel
  • Do your actions
  • Go to Developer > Stop Recording
    Stop Recording a Macro in Excel

When Recording a Macro there are two options: ‘Use Relative References’ or not.

Excel VBA - Use Relative References

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:

VBA Macro Recorder - Relative References

Run a Macro

To run a macro, navigate to the Developer Ribbon and select Macros:

Excel VBA Macros for Beginners

Then select your desired Macro and click Run:

Excel Macro Tutorial

Notice from this menu you can also select "Edit". Edit will open the code for that macro within the Visual Basic Editor.

AutoMacro - VBA Coding Made Easy

AutoMacro is a VBA add-in that makes coding easier for everyone:

VBA for Beginners

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.

If you find this site useful, please upvote us on Quora.

After going through the tutorial check out our VBA Code Examples