Introduction to Macros in Excel

Macros are a powerful tool in Excel that allows users to automate repetitive tasks. A macro is essentially a recorded sequence of actions in Excel that can be replayed anytime. These are especially useful for performing tasks that are repetitive or involve multiple steps.


Steps to Record and Run a Macro

Step 1: Enable the Developer Tab

  1. Click on File > Options > Customize Ribbon.
  2. Under the right panel, check the Developer option, and click OK.

Step 2: Record a Macro

  1. Go to the Developer tab and click Record Macro.
  2. In the dialog box:
    • Enter a Macro Name (e.g., “FormatTable”).
    • (Optional) Assign a Shortcut Key (e.g., Ctrl+Shift+F).
    • Choose where to store the macro (e.g., This Workbook).
  3. Perform the actions you want to record. For example:
    • Select a range of cells.
    • Apply formatting (bold, borders, colors).
    • Insert a formula.
  4. When done, click Stop Recording in the Developer tab.

Step 3: Run the Macro

  1. Select where you want to apply the macro.
  2. Go to Developer > Macros.
  3. Select the macro you recorded and click Run.

Example: Creating a Macro to Format a Table

Scenario: You have sales data that needs to be formatted repeatedly.

Sample Data

MonthSales
January5000
February6000
March7000

Steps to Automate:

  • Apply a bold font to headers.
  • Apply borders to the table.
  • Format the Sales column as currency.
  1. Start recording a macro.
  2. Select the data, apply bold to the headers, format the Sales column, and add borders.
  3. Stop recording.
  4. Run the macro for similar datasets in the future.

Best Practices for Using Macros

  • Use descriptive names for macros.
  • Store macros in the Personal Macro Workbook if you want them available across all workbooks.
  • Test your macro on a sample dataset first.
  • Save the workbook as Excel Macro-Enabled Workbook (*.xlsm) to retain macros.