What Is the Use of Macros in Excel with Examples

If you just need to what is the use of macros in excel with examples and move on, the boxed answer at the top is all you need. The rest of this page is for when you want to understand why it works in Excel, adapt it to a trickier version, or make it robust enough to hand to a colleague. We keep the opening short on purpose — the depth is here when you want it, not in your way when you don’t.

Exact answer

In Excel: A macro is a named list of Excel actions stored in the workbook and replayed on demand; VBA (Visual Basic for Applications) is the language those actions are written in.

VBA macro: What a Macro Is in Excel

Sub FormatSalesReport()
    Dim ws As Worksheet
    Dim lastRow As Long
    Set ws = ActiveSheet
    lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
    ws.Range("A1:D1").Font.Bold = True
    ws.Range("A1:D1").Interior.Color = RGB(221, 235, 247)
    ws.Range("A1:D" & lastRow).Borders(xlInsideHorizontal).LineStyle = xlContinuous
    ws.Columns("A:D").AutoFit
    MsgBox "Header styled, gridlines added and columns A:D auto-fitted down to row " _
           & lastRow & ".", vbInformation
End Sub

Five ordinary formatting actions — bold the header, shade it, rule the rows down to the last one with data, widen the columns, report back. A macro is nothing more exotic than that list, written down so Excel can repeat it on demand. lastRow here is a row NUMBER, not a count of rows, which is why the message names the row it stopped at rather than claiming a total.

How to run this macro

  1. Press Alt + F11 to open the VBA editor.
  2. Insert > Module.
  3. Paste the code above.
  4. Press F5, or close the editor and run it from Developer > Macros.
  5. Save the file as .xlsm so the macro is kept.
Annotated stepsExcel
1

Decide whether the job is repetitive enough to be worth automating — a task done once is faster by hand.

2

Press Alt + F11 to open the VBA editor and use Insert ▸ Module to create somewhere for the code to live.

3

Write or record the sequence of actions between Sub Name() and End Sub.

4

Run it with F5 in the editor, or from Developer ▸ Macros on the sheet, and check the result on a copy of your data.

5

Save the file as .xlsm — the .xlsx format cannot store VBA and drops it silently.

Ctrl+CthenCtrl+Shift+V+Cthen+Ctrl+VPaste values · WindowsMac

What this does

A macro is a sequence of Excel actions written down under a name so the program can replay them. The two words people meet first mean slightly different things: a macro is the recorded or written procedure, while VBA — Visual Basic for Applications — is the programming language it is expressed in, and it is the same language across Excel, Word, Access and Outlook. In practice a macro is a block of text beginning with Sub, a name, and a pair of brackets, and ending with End Sub. Everything between those two lines runs top to bottom when you invoke it. Macros reach the parts of Excel that formulas cannot: a formula computes a value inside its own cell, whereas a macro can rename sheets, delete rows, apply formatting, open other files, drive Outlook, or ask the user a question and branch on the answer. Most people learn this as a sequence of clicks and forget it by next week; learning it as a pattern instead is what lets you apply it to the next, slightly different version of the problem without starting from scratch. That is the difference this page is trying to make. Treat “what is the use of macros in excel with examples” as a small repeatable workflow rather than a one-off click you hope to remember next time. Use a small test block before the live file, so any surprise in the affected cells shows up while it is still harmless. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That turns a workflow that saves repeating the same clicks every week into a method you can reuse, explain, and defend when the workbook leaves your screen.

A worked example

Suppose the report you build every Monday means bolding the header row, shading it pale blue, ruling the rows, widening four columns, and confirming where the data ends. Done by hand that is a dozen clicks; recorded or written once as Sub FormatSalesReport() it becomes a single keystroke, and it does exactly the same thing on the tenth run as on the first. Realistic jobs macros are used for: merging twelve monthly exports into one sheet; emailing a filtered copy to each regional manager; stripping the rows where a status column reads "closed"; converting a folder of workbooks to PDF overnight. What they are not good at is anything a formula already does well — a macro that recalculates a total is slower and more fragile than =SUM(). Knowing what a macro is decides whether you need one at all. The honest answer for most spreadsheet problems is no — a formula or a PivotTable is easier and reversible. Macros earn their keep on the jobs that repeat, that touch many files, or that reach outside Excel entirely. One habit worth forming early: name the cells that hold your inputs, so the formula reads in plain language instead of a string of cell addresses. A reviewer — or you in three months — can then follow the logic without decoding what B7 and D2 were supposed to mean, which is most of what makes a sheet maintainable.

In Google Sheets

If you are in Google Sheets rather than Excel, the good news is that the formula shown here is identical and the workflow barely changes — menus sit across the top instead of in a ribbon, and a few function names differ slightly, but anything you build here moves across with little or no rework. Keep this page bookmarked for the next time the same question comes up. Better still, rebuild the example once in your own sheet — doing it yourself, with the tool above to check against, is what turns a copied formula into a technique you own. The short version of “what is the use of macros in excel with examples”: the answer is at the top of this page, the tool proves it on your own numbers, and the sections above explain why it holds so the next variation does not stump you. Excel rewards people who reference cells instead of typing values and who keep inputs separate from formulas, because that is what makes a result you can audit months later. Build it once, deliberately, with the live tool as a check, and you convert a one-off lookup into a reusable skill — which is the whole point of learning the why and not just the what.

Common mistakes

  • Treating "macro" and "VBA" as different tools. They are one thing seen from two sides: the macro is the procedure, VBA is the language it is written in. There is no separate macro language to learn.
  • Reaching for a macro where a formula, a PivotTable or Power Query would be simpler. Macros cannot be undone with Ctrl + Z, so any job a built-in feature already covers is safer left to the built-in feature.
  • Believing macros are inherently dangerous. The code is only as risky as its author — the reason Excel blocks them by default is that a workbook from an unknown sender can carry hostile VBA, not that automation itself is unsafe.
  • Expecting a macro written on Windows to run unchanged on Mac. File paths, Outlook automation and some ActiveX controls differ, so cross-platform macros need testing on both.

Frequently asked questions

Is a macro the same thing as VBA?

Almost. The macro is the saved procedure; VBA is the programming language it is written in. You write a macro in VBA, so in everyday use the words are interchangeable.

What can Excel macros actually do?

Anything you can do through the interface, plus things you cannot: loop over thousands of rows, open and combine other workbooks, send Outlook mail, export PDFs, create sheets and charts, and prompt the user for input mid-run.

Do I need to be a programmer to use one?

No. The macro recorder under Developer ▸ Record Macro turns your clicks into VBA you can read and reuse, which is how most people start. Writing from scratch comes later, if at all.

Are macros still supported in Microsoft 365?

Yes. VBA is fully supported in current desktop Excel on Windows and Mac. It does not run in Excel for the web, where Office Scripts (TypeScript) fills the same role.

Other ways people ask this

People reach this page typing “what is excel vba” and “what is the use of macros in excel”, among other phrasings; whichever wording you used, the fix above is the one you want.

Why do people search for this in so many different ways?

Because the same task has many names. “what is excel vba”, “what is the use of macros in excel” all point at the one operation explained on this page, which is why they all lead here.