Excel Macro & Advanced Filter how to use
⚡ Golden Web Tools
Your complete guide to automating Excel with macros (recording & VBA) and mastering Advanced Filter with real examples.
📼 Macro & VBA record + code
Macro = record actions (no coding). VBA = write custom logic with variables, loops, and conditions.
🎬 1. Record a Macro
- Show Developer tab: File → Options → Customize Ribbon → check Developer.
- Go to Developer → Record Macro.
- Name:
FormatHeader(no spaces). Shortcut: Ctrl+Shift+H. - Store in: This Workbook (so it travels with the file).
- Perform actions: select row 1, bold, center, fill gold.
- Click Stop Recording.
- Run: shortcut Ctrl+Shift+H or Developer → Macros → Run.
💡 The recorder captures absolute references by default. Use relative references for flexibility.
🧑💻 2. Write VBA Code
Press Alt+F11 to open VBA editor. Insert a module and paste:
🔁 VBA loop iterate through rows and apply logic:
Dim, If...Then, For Each, Do While.
⚠️ VBA changes cannot be undone with Ctrl+Z. Always keep a backup.
🔍 Advanced Filter criteria · extract
Filter with complex logic (AND / OR) and copy results to a new location or in‑place.
📋 The 3 Components
- List Range: your data table (must have headers).
- Criteria Range: headers + conditions. Same row = AND, different rows = OR.
- Extract Range: (optional) destination for filtered rows. Only headers needed.
📐 Criteria Rules – detailed
- Same row → AND (e.g. Region = "East" AND Sales > 5000)
- Different rows → OR (e.g. Region = "East" OR Region = "West")
- Wildcards:
*(any characters),?(one character). - Blanks:
==· Non‑blanks:<> - Formula criteria: use a formula (e.g.
=B2>AVERAGE(B:B)). The header in criteria must be blank or different from data header.
⚙️ Step‑by‑step example
Data: Name (A), Region (B), Sales (C) in rows 1–100.
- Set criteria: type header Region in E1, Sales in F1. In E2:
East, in F2:>5000. - Set extract headers: in E5:G5 type
Name,Region,Sales. - Go to Data → Advanced.
- Action: Copy to another location.
- List range:
$A$1:$C$100· Criteria:$E$1:$F$2· Copy to:$E$5. - Click OK → all East sales >5000 appear.
Criteria:
Region → East (row2) Region → West (row3) → returns all rows where Region is East or West.
📌 Advanced Filter with formula
Dynamic criteria using a formula – no hard‑coded values.
⚡ Advanced Filter is a one‑time snapshot. Re‑run to refresh results if data changes.
🧾 Macro Recorder – full process
- Select range (e.g. A1:D1) before recording.
- Developer → Record Macro → name, shortcut, store in “This Workbook”.
- Apply formatting: bold, center, fill colour, borders, etc.
- Stop Recording.
- Test: select another range and press shortcut or run from Macros.
- View code: Alt+F11 → Modules →
FormatHeader.
📊 Advanced Filter – extra examples
- Extract unique list: Data → Advanced → Unique records only → copy to new location.
- Mixed AND/OR:
Row2:Sales > 5000ANDRegion = East
Row3:Region = West
→ (Sales >5000 AND East) OR West. - Wildcard:
J*in Name column finds “John”, “Jane”, etc. - Case insensitive – Advanced Filter is not case‑sensitive.
🧩 VBA in action – more examples
📌 Loop with condition
📌 Message box & input
📋 Advanced Filter – full process with example
$A$1:$C$100 (headers: Name, Region, Sales)E1:F2 → header: Region / Sales row2: East / >5000 (AND condition)
$E$5:$G$5 (headers: Name, Region, Sales) – only top row needed.Region:
South → now returns East, West, or South.
Built with ❤️ for productivity · all processes shown with real examples.