Courses โ€บ VBA Basics

What VBA Is and When to Use It

Lesson 1 of 8 ยท 6 min

A programming language that lives inside Excel

VBA stands for Visual Basic for Applications. It is built into Excel already โ€” there is nothing to download and nothing to install. You write instructions, and Excel carries them out: the same clicks you would make by hand, but in a fraction of a second and in exactly the same way every single time.

Good reasons to write a macro

  • Repetition โ€” the same clean-up on a new export every Monday morning.
  • Volume โ€” 40,000 rows, where doing it by hand would cost you an afternoon.
  • Consistency โ€” a report that must come out formatted identically each month.
  • Things formulas simply cannot do โ€” creating sheets, saving files, printing, or showing a dialog box.

When not to use VBA

If a formula, a PivotTable or Power Query already solves the problem, use those instead. They are easier for a colleague to understand and they survive being emailed around. Macros need a macro-enabled file, they can be blocked by security settings, and somebody has to maintain them. Reach for code when the built-in tools genuinely run out of road โ€” not before.

Macro-enabled files

A normal .xlsx workbook cannot store code at all. When you save a workbook that contains a macro you must choose Excel Macro-Enabled Workbook (.xlsm). If you save it as .xlsx, Excel silently throws the code away โ€” with a warning that is very easy to click straight past. When you reopen an .xlsm file, Excel shows a yellow security bar; click Enable Content or the macros will not run.

What a macro actually is

A macro is just a named block of instructions stored in your workbook. You give it a name, Excel remembers it, and you run it whenever you like from the macro list, a keyboard shortcut, or a button on the sheet. Everything else in this course is detail on top of that one idea.

๐Ÿ’ก Before you automate anything, do the task once by hand and write down every step in plain language. That numbered list becomes the outline of your macro.
Knowledge check
Which file format keeps your VBA code when you save the workbook?

Sign in to answer and track your progress.

Sign in
Continues in this course
  • ๐Ÿ”’ The Visual Basic Editor 6 min
  • ๐Ÿ”’ Your First Macro 7 min
  • ๐Ÿ”’ Sub, End Sub, and Procedure Names 6 min
  • ๐Ÿ”’ Variables, Dim, and Option Explicit 7 min
  • ๐Ÿ”’ Talking to the User: MsgBox and InputBox 6 min
  • ๐Ÿ”’ Comments and Readable Code 5 min
  • ๐Ÿ”’ Running Code and Fixing It When It Breaks 7 min

Pro unlocks these 7 lessons, the final exam and the certificate โ€” plus every other course.

Unlock all lessons