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.
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.
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 method | Skill required | Power level | Best for |
|---|---|---|---|
| Recorded macros | None — just click Record | Basic — replays exact steps | Formatting, sorting, simple transformations |
| Edited VBA macros | Basic VBA understanding | Intermediate — adds logic | Conditional steps, loops, error handling |
| Custom VBA functions | VBA programming | Advanced — creates new functions | Calculations Excel does not have built in |
| Power Query | GUI-based, no coding | High — transforms and cleans data | Importing, merging, and reshaping data from multiple sources |
| Office Scripts (Excel Online) | TypeScript | Intermediate | Automation 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.
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.xlsxfiles 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 element | What it means | Analogy |
|---|---|---|
Sub ... End Sub | Defines the macro (start and end) | The recipe card |
Range("A1:E100").Select | Selects cells A1 through E100 | "Open the drawer" |
.Font.Bold = True | Makes text bold | "Highlight with a marker" |
.NumberFormat = "$#,##0.00" | Sets currency format | "Add dollar signs" |
' This is a comment | Explanatory note (ignored by VBA) | A sticky note on the recipe |
Plan a Macro
25 XPCustom 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
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 level | What it does | Trade-off |
|---|---|---|
| Disable all macros without notification | Silently blocks all macros | Maximum security, zero automation |
| Disable all macros with notification | Blocks macros but shows a warning bar | Good balance — you can enable trusted macros |
| Disable all macros except digitally signed | Only runs macros from verified publishers | Enterprise standard |
| Enable all macros | Runs everything automatically | Maximum risk — never use this |
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.
Automate or Formula?
50 XP2. Every Friday, copy this week's data from the "Raw" sheet, paste it into the "Archive" sheet below existing data, then clear the "Raw" sheet →
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?