To learn VBA coding in Excel, start by recording simple macros to see how Excel writes code, then open the Visual Basic Editor to read and edit that code, and finally practice writing small procedures that automate one task at a time. You do not need programming experience, but you do need a desktop copy of Excel (Windows or Mac) because the full VBA editor is not available in Excel for the web or on mobile.

What You'll Need

  • A desktop version of Microsoft Excel (Microsoft 365, Excel 2019, or later) on Windows or Mac. The VBA editor is not available in Excel for the web, iPad, or Android.
  • The Developer tab enabled in Excel options (labels can differ slightly by version and platform).
  • A sample workbook you can experiment in without risking important data.
  • Basic familiarity with Excel formulas and cell references.

Step-by-Step

  1. Enable the Developer tab. On Windows, go to File > Options > Customize Ribbon and tick Developer in the right-hand list. On Mac, go to Excel > Preferences > Ribbon & Toolbar and tick Developer. The exact wording may vary slightly by version.
  2. Record your first macro. On the Developer tab, click Record Macro. Give it a name (no spaces), choose This Workbook as the store location, and perform a simple action such as formatting a range or entering a formula. Click Stop Recording. This shows you the syntax Excel generates.
  3. Open the Visual Basic Editor (VBE). Press Alt+F11 on Windows, or Option+F11 on Mac, or click Visual Basic on the Developer tab. In the Project Explorer, find your workbook and expand Modules to see the recorded code.
  4. Read the recorded code line by line. Notice the pattern: Sub Name() ... End Sub, and how actions like Range("A1").Value = "Hello" map to what you did. Do not worry about memorising; focus on recognising structure.
  5. Write a minimal procedure from scratch. Insert a new module (Insert > Module) and type a short Sub that writes text to a cell, for example: Sub WriteHello() Range("A1").Value = "Hello" End Sub. Press F5 to run it and confirm the result.
  6. Learn variables and basic logic. Practice declaring variables with Dim, assigning values, and using If...Then...Else and simple For...Next loops. Use the Immediate Window (Ctrl+G in the VBE) to test expressions like ?Range("A1").Value.
  7. Work with ranges and worksheets. Practice referring to Worksheets("Sheet1").Range("A1:B10"), copying values, and looping through cells. Use the macro recorder again whenever you are unsure of the correct syntax for an action.
  8. Add error handling and comments. Wrap risky code in On Error GoTo handlers and add apostrophe comments to explain each block. This makes your code easier to debug and revisit.
  9. Build one small project. For example, a macro that cleans a data table, or a button on the sheet that runs a report. Break the task into small steps and test after each addition.
  10. Use official references. Rely on Microsoft's VBA documentation and the built-in Object Browser (F2 in the VBE) to look up objects, methods, and properties. Avoid copying code you do not understand.

Common Mistakes

  • Recording macros with unnecessary selections (Select, Activate) instead of working directly with ranges.
  • Forgetting to declare variables or using Variant everywhere, which hides type errors.
  • Running code on the wrong worksheet because the active sheet was not specified.
  • Saving a workbook with macros as .xlsx, which strips the VBA code. Use .xlsm instead.
  • Ignoring error handling, so a single unexpected value stops the whole macro.

Tips

  • Use the macro recorder as a syntax dictionary, then clean up the generated code.
  • Test each new line or block in a copy of your workbook before running it on real data.
  • Use Option Explicit at the top of each module to force variable declaration.
  • Keep procedures short and give them descriptive names.
  • Back up your workbook before running unfamiliar code, because macros can change or delete data.

Troubleshooting

If a macro does not appear to run, check that macros are enabled for the workbook (File > Options > Trust Center > Trust Center Settings > Macro Settings) and that the file is saved as .xlsm. If you get a compile error, use Debug > Compile VBAProject to locate the line. If the code runs but produces wrong results, step through it with F8 and watch values in the Locals window. If the Developer tab is missing, recheck the ribbon customisation step. If the VBE will not open, close and reopen Excel, and confirm you are using the desktop app rather than the web version.

Frequently Asked Questions

Can I learn VBA in Excel for the web or on mobile?

No. The VBA editor is only available in the desktop versions of Excel for Windows and Mac. Excel for the web and mobile apps do not include it.

Do I need to know programming before starting VBA?

No. Basic Excel skills and willingness to experiment are enough; the macro recorder helps you see working code immediately.

How long does it take to learn VBA?

It varies by person and practice time. You can automate simple tasks within days, while comfortable, robust coding takes weeks of regular practice.

Is VBA still supported?

Yes, VBA remains available in desktop Excel. Microsoft recommends newer automation tools for some scenarios, but VBA is still supported for existing and new macros.

Why did my macro disappear after saving?

The workbook was likely saved in the .xlsx format, which does not store macros. Save as .xlsm to keep the code.

Can macros harm my computer?

Macros can change or delete files and, in malicious files, do more. Only enable macros in workbooks from trusted sources, and keep macro security settings at the recommended level.