excel vba tutorial

The Ultimate Excel VBA Tutorial

Welcome to the ultimate Excel VBA Tutorial (Visual Basic for Applications)! You will walk the journey from being an VBA Zero to becoming an VBA Hero. This VBA tutorial is not aimed only at teaching you how to write VBA macros in Excelit’s a general introduction to VBA. However, some sections as you will notice are indeed aimed at Excel (e.g. the Workbooks and Worksheets section).

Prefer books? Checkout my recommended VBA books
Prefer learning from videos? Checkout my recommended VBA Video Tutorials

Visual Basic Editor Tutorial

To start programming in VBA you need to be able to access the Developer ribbon tab in Excel to open the VBA Developer environment (VBE). Read the article to learn how to:

You will learn:

  • Enable the Excel Developer ribbon tab
  • Walkthrough of the VBE windows
  • Shortcuts how to open the VBA window

How to Record Macros

Recording macros is a great way to test and learn writing new code. Simply record a series of steps and see what the output code looks like instead of Googling it.

You will learn:

  • Record your first Excel macro
  • Run the recorded macro
  • Review the generated code

How to Debug VBA

Debugging code is the process of line by line code execution often to understand the process and to identify and resolve macro runtime errors. Learning to debug VBA code in the Excel VBE is key skill.

You will learn:

  • How to Run, Break or Reset your code
  • Learn what are breakpoints and how to use them
  • See how to run your code step by step and the various debugging shortcuts

VBA Functions and Procedures

To execute VBA Code you need to start with a VBA Sub (procedure). VBA Functions on the other hand allow you process and input to return and output that can be used for other purposes.

You will learn:

  • Create your first Hello World VBA macro using a VBA Sub
  • Learn the basics of VBA Subs as well as how they are different from VBA Functions
  • Understand how you can pass arguments to a Sub/Function

VBA Variables

In order to process data you need to store it somewhere. In this tutorial you will learn how to use the VBA Dim statement to declare VBA Variables and all Data Types available in VBA (strings, numbers etc.).

You will learn:

  • The available data types in VBA
  • How to declare and define variables
  • Constants vs Variables
  • Private vs Public Variables

VBA Conditions – If…Else

Making decisions is hard, but a must in programming. The VBA If…Then…Else statement is a basic conditional statement for making simple boolean decisions in your VBA code.

You will learn:

  • The If…Else statement to run code basis conditions met
  • Boolean operators such as <, = etc.
  • The Iif function

VBA Select Case

The VBA If statement is great for writing several conditions. In some cases, however, there is a need to enumerate many scenarios based on values of specific variables. The VBA Select Case statement saves a lot of time compared to VBA If.

You will learn:

  • The Switch…Case statement to run several conditions basis a single variable
  • Case Is statment

Using VBA Loops: For, ForEach

VBA For loops are necessary for running a scope of code several times, enumerating through tables or running code in a simple loop.

You will learn:

  • The For…Next statement to run iterations basis a variable
  • The ForEach…Next statement iterate a collection
  • For vs ForEach and when each should be used

Using VBA Loops: Do While, Do Until

VBA For loops allow you to run a loop for a specific amount of iterations. For cases when a loops needs to be run until a condition is met (Do Until) or needs to run while a condition is met (Do While), read the tutorial.

You will learn:

  • Do…While and Do…Until loops
  • How to exit / continue a Do…While Loop

Excel VBA Range

Learn how to change values of cells in Excel, change the format of an Excel Range etc. Go to the tutorial to learn everything of how to interact in your VBA Macro with an Excel worksheet.

Excel Cells Formatting

Learn in this tutorial to format Excel cells – change their size, background color, borders, style and more.

VBA UserForm

UserForms allow you to create you own pop-up windows for users to interact with, similar to Message Boxes.