Macro
A macro is a set of recorded actions or instructions in Excel that you can play back
to automate repetitive tasks. For example, if you often:
Format a report the same way,
Apply filters,
Generate charts,
You can record a macro once and reuse it with one click.
Example Use Case:
Applying consistent formatting to a sales report every month.
Automatically inserting a date stamp and saving the file.
VBA (Visual Basic for Applications)
VBA is the programming language behind Excel macros. While macros can be
recorded, VBA allows you to write or edit code to make your automation more
powerful and flexible.
Think of VBA as the engine, and macros as the shortcut button you press to run that
engine.
With VBA, you can:
Create custom functions (beyond what Excel offers).
Interact with other Office apps (like Outlook, Word).
Build user forms and dashboards.
Add error handling and decision-making (e.g., If-Else, Loops).
Example: A Simple VBA Macro
vba
CopyEdit
Sub HighlightNegativeNumbers()
For Each cell In Selection
If cell.Value < 0 Then
cell.Font.Color = vbRed
End If
Next cell
End Sub
This code highlights any negative numbers in the selected range in red.
Security Note
Macros and VBA can be used maliciously, so Excel may block them by default in
downloaded files. Always be cautious and only enable macros from trusted sources.