Ravindra BagaleCourses & study guides Track your progress

Guides

Record Your First Excel Macro (No Coding Needed)

Every morning Ravina downloads the same sales export and spends ten minutes making it readable: bold green header, rupee format, column widths. She records those clicks once as a macro. Now the same formatting takes one shortcut: Ctrl + Shift + R.

A macro is a recorded set of actions saved as VBA code. Developer > Record Macro writes down your clicks and typing until you click Stop Recording; running the macro repeats them. Save the file as an Excel Macro-Enabled Workbook (.xlsm) or the macro is lost.

The names and numbers in the examples are fictional teaching data.

Quick answer

  1. Show the Developer tab: File > Options > Customize Ribbon, tick Developer, OK.
  2. Click Developer > Record Macro. Name it FormatReport (no spaces), shortcut Ctrl + Shift + R, store in This Workbook, OK.
  3. Do the formatting steps once, carefully.
  4. Click Developer > Stop Recording.
  5. Save with File > Save As > Excel Macro-Enabled Workbook (*.xlsm).

Record it

  1. Open the export and click cell A1.
  2. Developer > Record Macro, fill the name and shortcut, click OK. Everything you do now is recorded.
  3. Select A1:F1, make it bold, fill it green and set the font white.
  4. Select column F and apply your rupee number format.
  5. Select columns A:F and double-click a column border to autofit.
  6. Click A2, then Developer > Stop Recording.

Absolute or relative?

By default the recorder remembers exact cells (A1:F1). Click Developer > Use Relative References before recording if the macro should work from wherever the active cell is, for example "format the row I am on".

Run it

  • Press the shortcut Ctrl + Shift + R.
  • Or press Alt + F8, pick FormatReport and click Run.
  • Or add a button: Developer > Insert > Button (Form Control), draw it, pick the macro.
  • Or right-click the Quick Access Toolbar > Customize, choose Macros and add it.

Macros cannot be undone with Ctrl + Z. Try a new macro on a copy of the file first.

Look at the code Excel wrote

Press Alt + F11 to open the VBA editor and double-click Module1. A cleaned-up version of what the recorder writes looks like this:

Sub FormatReport()
    ' Recorded macro: bold header, Indian rupee format, autofit
    Range("A1:F1").Font.Bold = True
    Range("A1:F1").Interior.Color = RGB(33, 115, 70)
    Range("A1:F1").Font.Color = RGB(255, 255, 255)
    Columns("F:F").NumberFormat = "[$₹-4009] #,##,##0"
    Columns("A:F").AutoFit
    Range("A2").Select
End Sub

Recorded code often has extra Select lines and scroll steps. You can delete them; the macro still works. Changing "A1:F1" to another range is the first easy edit most people make.

Saving and security

  • .xlsx cannot store macros. Excel warns you when you save; choose .xlsm.
  • When you open an .xlsm, Excel may show a security bar. Enable content only for files you trust.
  • Files downloaded from the internet may have macros blocked. Right-click the file > Properties > tick Unblock if it is from a trusted source.
  • To use a macro in every workbook, store it in the Personal Macro Workbook while recording.

Ravindra Bagale's Tip

Before you record, rehearse the steps once without recording and write them down in order. A macro records your mistakes too, and a clean five-step recording is easier to fix later than a messy fifteen-step one.

Practice task

  1. Turn on the Developer tab.
  2. Type a small list with headers in A1:F1 and a few rows of numbers.
  3. Record the FormatReport macro with the steps above and stop recording.
  4. Clear the formatting (Home > Clear > Clear Formats) and run the macro with Ctrl + Shift + R.
  5. Save the file as .xlsm, close it, reopen it and run the macro again.

Frequently asked questions

Why is my macro gone after saving?

The file was saved as .xlsx, which cannot keep macros. Record again and save as .xlsm.

Do macros work in Excel for the web?

No. VBA macros run in desktop Excel. Excel for the web uses Office Scripts instead.

Can I undo a macro?

No. Ctrl + Z does not undo macro steps, so test on a copy first.

Is a recorded macro safe to share?

Yes if it only formats or moves your own data. Colleagues will see a security prompt; tell them what the macro does.