Excel VBA Course: Learn Macros Step by Step
In this article
An Excel VBA course teaches you to automate repetitive spreadsheet work by writing small programs called macros. You do not need programming experience to start, and you do not need a paid course: Excel includes a macro recorder and a full code editor, so you can build a self-paced curriculum from recording your first macro today to writing loops and functions that handle whole workbooks. The fastest path is to record a macro you actually repeat weekly, open the recorded code, edit it, then gradually replace recorded lines with your own variables, loops and error handling.
What You'll Need
- A desktop copy of Excel on Windows or Mac. The macro recorder and Visual Basic Editor are not available in Excel for the web, and the mobile apps cannot run or edit VBA at all. Labels can differ slightly by version, device and region, so a menu name below may appear with slightly different wording on your machine.
- The Developer tab enabled. If you do not see it, open File > Options > Customize Ribbon (on Mac, Excel > Preferences > Ribbon & Toolbar) and tick Developer in the right-hand list.
- Macro security set to allow macros in files you trust. Look under Developer > Macro Security. Choose the setting that disables macros with notification, then enable them per file, rather than the lowest setting that runs everything silently.
- A practice workbook you can break without consequences, saved as .xlsm (macro-enabled). Plain .xlsx files cannot store VBA code.
- A keyboard shortcut you will remember for opening the editor: Alt+F11 on Windows, or Option+F11 on Mac for most layouts.
- Optional: a second monitor or a split view, so you can watch your spreadsheet while stepping through code.
Step-by-Step
- Decide what to automate first. Write down one task you repeat at least weekly: formatting a report, cleaning imported data, copying rows to another sheet, building a summary table. A real task keeps you motivated far better than an abstract exercise, and it gives you a test case to check your code against.
- Save a copy of the workbook as .xlsm. Use File > Save As and pick the macro-enabled format. Doing this before you record anything prevents the warning that appears when you try to save VBA into a standard workbook.
- Record your first macro. Go to Developer > Record Macro, give it a descriptive name with no spaces (for example FormatMonthlyReport), choose whether to store it in the current workbook or your Personal Macro Workbook, and optionally assign a shortcut key. Perform the task slowly and deliberately, then click Stop Recording. Avoid unnecessary clicks and scrolling while recording, because every selection you make is written into the code.
- Read the generated code. Open the Visual Basic Editor and look at the new module. You will see lines like Range("A1").Select and Selection.Font.Bold = True. Read them aloud: the recorder writes exactly what you did, including mistakes. This reading stage is where most of the learning happens.
- Clean up the recording. Recorded code is full of Select and Activate statements. Replace them with direct references so the macro works without changing what is on screen. For example, instead of selecting a range then bolding it, write Worksheets("Report").Range("A1:D1").Font.Bold = True. Set Application.ScreenUpdating = False at the start and True at the end to speed things up.
- Learn the five building blocks. Work through these in order, writing a tiny exercise for each: variables and data types (Dim total As Double), objects and collections (Workbook, Worksheet, Range), conditionals (If ... Then ... Else ... End If), loops (For Each cell In Range and For i = 1 To 10), and Sub versus Function procedures. A Function returns a value and can be called from a cell; a Sub performs actions.
- Practice with one worked example. Build a macro that loops down column A of a data sheet, checks each value with an If statement, and writes a status into column B. This single exercise touches reading cells, testing conditions, writing results, and finding the last used row, which is the most important pattern in real VBA. Find the last row with Cells(Rows.Count, 1).End(xlUp).Row rather than a fixed number.
- Add error handling and basic input. Wrap the body of your macro in On Error GoTo Handler and add an Exit Sub label before the handler so errors are reported rather than silently crashing. Use InputBox for a value the user must supply and MsgBox to report completion. Validate what comes back from an InputBox before using it.
- Assign macros to buttons and shortcuts. Insert a shape or form control button on the sheet (Developer > Insert), right-click it and choose Assign Macro. For a permanent shortcut, use Developer > Macros > Options and pick a key combination that does not clash with a built-in Excel shortcut.
- Test on a copy and step through the code. Press F8 in the editor to run one line at a time and watch values in the Locals window or by hovering over variables. Fix the macro against a duplicate of your real data before ever running it on the original.
- Keep going with a structured curriculum. After the basics, cover working with multiple workbooks, arrays for speed on large datasets, automating charts and pivot tables, UserForms for simple input screens, and the object model of whichever Office apps you use. A short project each week beats watching hours of video without typing anything.
Common Mistakes
The most frequent error is trusting recorded code without reading it: recordings capture stray selections and hard-coded cell addresses that break the moment data grows. Second is storing variables as the wrong type, usually Variant, which hides bugs; declare Integer, Long, Double and String deliberately, and always use Long for row numbers because Integer overflows on modern sheet sizes. Third is forgetting that VBA code lives in the workbook, so a colleague opening an .xlsm file must enable macros for anything to happen. Fourth is testing directly on live data with no backup. Fifth is using ActiveSheet or Selection references, which point at whatever happens to be in front at run time rather than the sheet you meant. Finally, novices skip On Error handling and then cannot tell why a macro stops halfway.
Tips
Name your variables and procedures clearly; future you will thank present you. Use Option Explicit at the top of every module so undeclared variables raise an error instead of silently becoming Variants. Break long macros into small Subs that each do one thing, and call them from a master routine. Comment the reason for tricky logic, not the obvious syntax. Keep a personal macro library in the Personal Macro Workbook for tools you use across files. Back up before running anything that deletes rows or sheets, and never leave Application.DisplayAlerts turned off permanently, because that suppresses confirmation prompts including overwrite warnings. Finally, learn to use the Immediate window with Debug.Print to inspect values without stopping the code.
Troubleshooting
If the Developer tab is missing, enable it through the ribbon customisation described above and restart Excel. If macros are greyed out or will not run, check Macro Security and confirm the file was saved as .xlsm in a trusted location. If the code errors with "Subscript out of range", a worksheet or workbook name in your code does not match the real one, including spelling and spacing. If it errors with "Object required", you are probably using Set incorrectly or referring to a cell without a Range. If a loop seems to run forever, add a counter and a maximum iteration guard, and confirm the loop actually changes the condition it tests. If results appear on the wrong sheet, replace ActiveSheet with an explicit Worksheets("Name"). If the macro is slow, switch off ScreenUpdating and Calculation around the main body and read data into an array instead of cell by cell. If Excel crashes or the file will not open after a bad edit, reopen in safe mode and remove the faulty module, restoring from your backup if needed. If the editor will not open at all, the workbook may have been opened from a network path with restrictive permissions; copy it locally and try again.
Frequently Asked Questions
Can I learn Excel VBA without any programming background?
Yes. The macro recorder shows you working code straight away, and the language is small enough to cover the basics of variables, loops and conditions in a few sessions.
Does VBA work in Excel for the web or on a phone?
No. Macros and the Visual Basic Editor require the desktop application on Windows or Mac. Files with macros open in the browser but the code does not run.
How long does a beginner course take?
It varies with the time you put in. Most learners can record, edit and debug simple macros within a few weeks of regular short practice, since progress comes from repetition rather than long sessions.
Do I need to buy an add-in or extra software?
No. Everything described here is built into desktop Excel. Third-party tools exist but are not required to learn.
Why does my macro only work on my computer?
Usually because it refers to file paths or workbook names that exist only on your machine. Use ThisWorkbook and relative paths, and share the workbook with clear instructions to enable macros.
Should I learn Power Query instead?
They solve different problems. Power Query is better for repeatable data cleaning and combining sources; VBA is better for automating formatting, interacting with other Office apps and custom logic. Learning both is common and useful.