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.
- Click Tools > Macros > Record a New Macro
- The Record Macro dialogue box appears. Enter a name for the macro
- 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.
- Click Format > Cells
- Select Date from the list of Categories on the Number tab
- Select the 14 March 2001 format and click Ok
- Click the Stop Recording button on the Visual Basic toolbar
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.
Let's complete the steps for the FormatDate macro.
That's it! A macro has been created. Let's run the macro to ensure it works as planned.
Run a macro
- Select the range that you wish to apply the date format to
- Click Tools > Macros > Macros
- Select the FormatDate macro and click Run
- The macro runs and formats the dates as planned
We will now assign the macro to a button.