Module 6

Automation & Macros

Stop doing the same 20 clicks every Monday morning — record a macro once and let Excel do the repetitive work for you forever.

💡What You'll Build
By the end of this module, you will be able to record a macro that automates any repetitive formatting or processing task, read basic VBA code well enough to edit recorded macros, create a custom VBA function, and know when to use Power Query instead of macros for data transformation.

An accountant at Deloitte automated her entire Monday morning in 2019

Every Monday, she received a CSV export from the billing system. She would open it, delete three header rows the system added, reformat the date column, add a currency format to the amount column, sort by client name, insert a subtotal row for each client, and save it as a formatted Excel file. The process took 45 minutes.

One day, she recorded a macro while doing the entire process. The next Monday, she opened the CSV, pressed Ctrl+Shift+M, and the macro replayed all 23 steps in under 4 seconds. She estimated that macro saved her 35 hours per year — nearly a full work week — on a single repetitive task.

Automation is not about replacing people. It is about freeing people from the tasks that do not require human judgment, so they can spend that time on work that does.

45 minmanual process time

4 secautomated macro time

35 hrssaved per year on one task

What is a macro?

A macro is a recorded sequence of actions that Excel can replay on command. Think of it like a recipe card: you write down the steps once, and anyone can follow them perfectly every time.

Behind the scenes, macros are written in VBA (Visual Basic for Applications) — a programming language built into Excel. When you "record" a macro, Excel watches what you do and writes VBA code that reproduces those exact steps. You do not need to know VBA to record a macro. You can learn VBA to write more powerful macros later.

Automation methodSkill requiredPower levelBest for
Recorded macrosNone — just click RecordBasic — replays exact stepsFormatting, sorting, simple transformations
Edited VBA macrosBasic VBA understandingIntermediate — adds logicConditional steps, loops, error handling
Custom VBA functionsVBA programmingAdvanced — creates new functionsCalculations Excel does not have built in
Power QueryGUI-based, no codingHigh — transforms and cleans dataImporting, merging, and reshaping data from multiple sources
Office Scripts (Excel Online)TypeScriptIntermediateAutomation in the cloud, Power Automate integration

Recording your first macro

Step 1: Enable the Developer tab — File → Options → Customize Ribbon → check "Developer"

Step 2: Developer → Record Macro → name it (e.g., "FormatReport"), assign a shortcut key (e.g., Ctrl+Shift+F), click OK

Step 3: Perform the actions you want to automate — format cells, sort data, delete rows, whatever the task requires

Step 4: Developer → Stop Recording

Step 5: Test it: undo everything you just did, then press your shortcut key. The macro replays all steps instantly.

⚠️Plan before you record
A recorded macro captures *every* click and keystroke — including mistakes. If you click the wrong cell and then correct yourself, both actions get recorded. Plan your steps before hitting Record. Practice the process once manually, then record it clean.

There Are No Dumb Questions

"Is there a macro recorder in Google Sheets?"

Google Sheets has a macro recorder (Extensions → Macros → Record macro), but it generates Google Apps Script (JavaScript-based) instead of VBA. The concept is identical — record actions, replay them. The language is different. If you learn the principles in Excel, they transfer directly.

"Will my macros work on someone else's computer?"

Only if the file is saved as .xlsm (macro-enabled workbook) instead of .xlsx. Regular .xlsx files strip out all macros when saved. Also, the recipient's Excel must allow macros to run — many corporate IT departments block macros by default for security reasons (macros can be used to deliver malware).

Peeking under the hood: basic VBA

When you record a macro, Excel writes VBA code. You can view it: Developer → Visual Basic (or Alt+F11). Here is what a simple formatting macro looks like:

Sub FormatReport()
    ' Select the data range
    Range("A1:E100").Select

    ' Bold the header row
    Rows("1:1").Font.Bold = True

    ' Format column D as currency
    Columns("D:D").NumberFormat = "$#,##0.00"

    ' Sort by column A
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range("A2"), Order:=xlAscending
    With ActiveSheet.Sort
        .SetRange Range("A1:E100")
        .Header = xlYes
        .Apply
    End With
End Sub

You do not need to memorize this. But understanding the structure helps you edit recorded macros:

VBA elementWhat it meansAnalogy
Sub ... End SubDefines the macro (start and end)The recipe card
Range("A1:E100").SelectSelects cells A1 through E100"Open the drawer"
.Font.Bold = TrueMakes text bold"Highlight with a marker"
.NumberFormat = "$#,##0.00"Sets currency format"Add dollar signs"
' This is a commentExplanatory note (ignored by VBA)A sticky note on the recipe

🔒

Plan a Macro

25 XP

You receive a weekly export from your CRM system. Every week, you need to: 1. Delete the first 2 rows (system-generated headers) 2. Auto-fit all column widths 3. Bold row 1 (the real headers) 4. Add a filter to all columns 5. Sort by "Close Date" column (column F) from newest to oldest 6. Save the file with today's date in the filename Which of these steps can a recorded macro handle? Which would require editing the VBA code? _Hint: Steps 1-5 can all be recorded. Step 6 (dynamic filename with today's date) requires VBA editing because the date changes each week — a recorded macro would save with the same filename every time._

Sign in to earn XP

Custom VBA functions — when Excel's built-in functions are not enough

Sometimes you need a calculation that does not exist in Excel's 500+ functions. VBA lets you create your own.

Example: A function that extracts the domain from an email address:

Function ExtractDomain(email As String) As String
    ExtractDomain = Mid(email, InStr(email, "@") + 1)
End Function

Now in any cell, you can type =ExtractDomain(A2) and it pulls "gmail.com" from "[email protected]". This function works like any built-in Excel function — you can copy it down an entire column.

Common custom function ideas:

  • Calculate business days between two dates (excluding holidays specific to your company)
  • Convert between unit systems your industry uses
  • Parse complex text patterns from imported data
  • Apply industry-specific scoring formulas
🔑Macros vs formulas — when to use which
Use formulas when the task is a *calculation* — transforming input values into output values in cells. Use macros when the task is an *action* — formatting, sorting, deleting rows, copying between sheets, saving files. If you find yourself writing complex nested formulas that are hard to maintain, a custom VBA function might be cleaner.

Macro security — why IT departments are scared of macros

Macros are powerful — which is exactly why they are dangerous. A VBA macro has full access to your file system, can download files from the internet, and can execute system commands. This is why macro-based malware has been one of the top attack vectors for decades.

Security levelWhat it doesTrade-off
Disable all macros without notificationSilently blocks all macrosMaximum security, zero automation
Disable all macros with notificationBlocks macros but shows a warning barGood balance — you can enable trusted macros
Disable all macros except digitally signedOnly runs macros from verified publishersEnterprise standard
Enable all macrosRuns everything automaticallyMaximum risk — never use this
⚠️Never enable macros from unknown sources
If you receive an Excel file from an unknown sender and it asks you to "Enable Content" or "Enable Macros," treat it like a phishing email — because it very likely is. Macro-based malware (like Emotet and TrickBot) has caused billions of dollars in damage globally. Only enable macros in files you created yourself or received from trusted, verified sources.

There Are No Dumb Questions

"Should I learn VBA in 2025, or is it outdated?"

VBA is 30+ years old and Microsoft is investing in newer technologies (Power Automate, Office Scripts, Python in Excel). But VBA is far from dead — it is embedded in billions of existing Excel files across every industry. Learning basic VBA is still practical for editing recorded macros, building custom functions, and maintaining legacy systems. Think of it like knowing how to drive a manual car — not always necessary, but useful when you encounter one.

"What is Power Query and how is it different from macros?"

Power Query is a data transformation tool built into Excel (Data → Get Data). It connects to external sources (databases, CSVs, web pages), cleans and reshapes data, and loads it into your spreadsheet. Unlike macros, Power Query uses a visual interface — no coding required. It is better than macros for data import and transformation tasks. Macros are better for formatting, multi-step workflows, and actions that involve multiple sheets or user interaction.

<classifychallenge xp="25" title="Which Automation Tool?" items={["Calculate 5% commission on deals over $10K, 3% otherwise","Every Friday, copy this weeks data to an Archive sheet and clear the Raw sheet","Import a CSV, remove system headers, unpivot monthly columns into rows","Create a custom shipping cost function based on weight, distance, and a proprietary rate table","Format all negative numbers as red, bold headers, add borders to all cells","Pull daily sales data from 3 regional CSVs, merge them, clean duplicates, and load into one summary table"]} options={["Formula (IF/IFS)","Recorded macro","Custom VBA function","Power Query"]} hint="Formulas are for calculations in cells. Recorded macros replay formatting and processing actions. Custom VBA functions create new calculation capabilities. Power Query handles data import, transformation, and merging from external sources.">

🔒

Automate or Formula?

50 XP

Classify 5 items into categories.

Sign in to earn XP

Back to the Deloitte accountant

Remember the accountant who turned 45 minutes of Monday drudgery into 4 seconds? She did not learn VBA programming. She did not hire a developer. She clicked Record, did the work one last time, and clicked Stop. That single recorded macro saved her 35 hours per year — nearly a full work week she reinvested in analysis that actually required her judgment.

The formulas you learned in Formulas & Functions handle calculations. The data analysis tools from the previous modules handle sorting, filtering, and summarizing. Macros handle the actions — the formatting, processing, and multi-step workflows that no formula can do. And for data import and transformation, Power Query handles what macros do clumsily.

Manual Monday

  • Open CSV from billing system
  • Delete 3 system header rows
  • Reformat date column
  • Add currency format to amounts
  • Sort by client name
  • Insert subtotal rows
  • Save as formatted .xlsx
  • Total: 45 minutes

Automated Monday

  • Open CSV
  • Press Ctrl+Shift+M
  • Macro replays all 23 steps
  • Save
  • Total: 4 seconds

Next up: Macros automate actions. But what about the formulas themselves — can they get more powerful? In the next module, you will learn dynamic arrays (FILTER, SORT, UNIQUE), LAMBDA functions, IFS, advanced text and date functions, and error handling — the formulas that separate competent Excel users from the ones everyone calls for help.

Key takeaways

  • Macros record sequences of actions and replay them on command — perfect for repetitive formatting, sorting, and processing tasks
  • Recording a macro requires zero coding knowledge — just click Record, perform the steps, and Stop
  • VBA is the programming language behind macros — learning the basics lets you edit recorded macros and add logic (loops, conditions)
  • Custom VBA functions create new formulas that work like built-in functions — useful when Excel's 500+ functions are not enough
  • Power Query is superior to macros for data import and transformation tasks — use the visual interface, no code needed
  • Macro security is critical — never enable macros from unknown sources, save macro files as .xlsm, and understand your organization's security policy
  • The automation mindset: if you do the same sequence of steps more than three times, automate it

?

Knowledge Check

1.You record a macro and accidentally click the wrong cell during recording, then correct yourself. What happens?

2.Why must macro-enabled workbooks be saved as .xlsm instead of .xlsx?

3.You need to import a CSV file, remove system-generated header rows, unpivot monthly columns into rows, and load clean data into a summary table every week. Which tool is best suited?

4.A colleague sends you an Excel file via email. When you open it, you see a yellow bar that says 'SECURITY WARNING: Macros have been disabled.' What should you do?