Excel > Excel 2003 Advanced > Macros

Record a Macro

A macro is an automated sequence of actions. It improves productivity by reducing a number of actions into one click of a button. This will make common tasks much quicker to perform.

The macro recorder is used to create macros in Excel. This is quick and easy to use, but is only capable of creating simple macros. Anything more powerful will involve writing VBA (Visual Basic for Applications) code. Using the macro recorder and then editing the macro is a great start before moving beyond the limitations of the recorder.

In this example, we wish to create a macro that formats a cell with a particular date format.

  1. Click Tools > Macros > Record a New Macro
  2. Record a macro
  3. The Record Macro dialogue box appears. Enter a name for the macro
  4. Macro names cannot contain spaces, begin with a letter or contain restricted symbols such as / and £.

    If the macro is to be used in this workbook only, select This Workbook from the Store macro in field. If the macro is to be used in any workbook, select Personal macro workbook.

    Enter a short description for the macro and click Ok.

    Record Macro dialogue box

  5. The macro is now recording each step that you take. It is recommended to have the necessary steps written down so that you may follow them. Unless you understand VBA code, any mistake at this point usually results in having to delete the macro and re-record it.
  6. Let's complete the steps for the FormatDate macro.

    1. Click Format > Cells
    2. Select Date from the list of Categories on the Number tab
    3. Select the 14 March 2001 format and click Ok
    4. Changing the date format

  7. Click the Stop Recording button on the Visual Basic toolbar
  8. Stop Recording button on toolbar

That's it! A macro has been created. Let's run the macro to ensure it works as planned.

Run a macro

  1. Select the range that you wish to apply the date format to
  2. Click Tools > Macros > Macros
  3. Select the FormatDate macro and click Run
  4. Selecting a macro to run

  5. The macro runs and formats the dates as planned

We will now assign the macro to a button.

Follow us on

Facebook  Twitter  You Tube