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.
Workbooks that contain macros need to be saved as a Macro Enabled Workbook. This can be done by clicking the Office Button, selecting Save As and then Excel Macro Enabled Workbook.
In this example, we wish to create a macro that formats a cell with a particular date format.
- Click the View tab on the Ribbon
- Click Macros and then Record Macro from the Macros group
- 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 the Home tab on the Ribbon
- Click the Number format drop list and click More Number Formats
- Select Date from the list of Categories on the Number tab
- Select the 14 March 2001 format and click Ok
- Click Stop Recording from the Macros button on the View tab
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 the View tab and then View Macros from the Macros button.
- 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.