✅ Advanced Excel Part 3: Macros and VBA Basics
1. What a Macro is
A macro records actions and replays them. You use it to
• Save time
• Reduce manual work
• Avoid repetitive clicks
Example
• Bold headers
• Apply borders
• Set number format
Run once. Excel repeats it exactly.
2. Macro Recorder. Best starting point
You do not write code. Excel writes it for you.
Steps
• View → Macros → Record Macro
• Perform actions
• Stop Recording
Result
A macro is created.
Example actions
• Format cells
• Insert rows
• Apply filters
Good for beginners. Limit
Recorded macros are not flexible.
3. Where macro code lives
Macros are written in VBA.
To open VBA editor
• Press Alt + F11
What you see
• Code window
• Modules
• Procedures
Each macro is a VBA procedure.
4. Simple VBA macro example
Sub FormatReport()
Range("A1:D1").Font.Bold = True
Range("A1:D1").Interior.Color = RGB(200,200,200)
End Sub
What this does
• Bolds header row
• Adds background color
You can run it anytime.
5. Running a macro
Ways to run
• Alt + F8 → Run
• Assign macro to a button
• Run from VBA editor
Button example
Click button → Report formats instantly.
6. When to use VBA
Use VBA when
• Logic is needed
• Conditions exist
• Loops are required
Example
• Highlight sales above target
• Send email for low stock
• Clean data automatically
7. Common beginner mistakes
• Forgetting to save file as .xlsm
• Disabling macros
• Hardcoding cell references
8. Safety note
Only enable macros from trusted files.
Interview tip
Say this clearly.
Macros automate repetitive tasks. VBA gives control using logic, conditions, and loops.
Double Tap ♥️ For More
Post #1908
4.82K
- ❤ 19