Creating a Macro
The easiest way to create a macro in Excel is by recording your steps with Excel's macro recorder. Then, the next time you want to perform these steps, you simply turn on the previously recorded macro and sit back with a nice cup of tea while you watch the macro do your work for you.
For example, if you would like to automate a task in Excel, you record yourself performing the task by turning on a little virtual tape recorder, which will record each step as you enter it. When you are finished entering your steps, you turn off the recorder, and presto! You have a macro! Well, almost. There are a few pieces of technical housework that must be performed, such as naming the macro and deciding where to store it, but for all practical purposes, macro recording is a fairly simple business.
We are going to create is a simple macro that places your name in a cell. Usually when we record macros, we try to record a task that we expect to use over and over again. So if placing your name in a cell is something you'll do a lot, this macro will work well for you by saving you a few keystrokes. If you use a company name frequently on your spreadsheets, or some other familiar text, you can enter that text in this macro instead of your own name.
Here are the steps to follow:
- With your Excel spreadsheet open, place your cellpointer in cell A1.
This way, we will all be in exactly the same place when we start recording this macro. - Click the Developer tab to open the Developer ribbon.
- Click the Record Macro button in the Code group of the Developer tab.
- In the Record Macro dialog box, as shown in Figure below, in the Macro Name field, enter Macro1 as the name of this macro. There can be no spaces in a macro name.
- In the Shortcut Key field, hold down the shift key and type m so that ctrl+shift+m will be the keyboard shortcut for this macro.
- In the Store Macro In field, choose "Personal Macro Workbook." This is the universal workbook that is accessible by all Excel spreadsheets. The other choices are "New Workbook" and "This Workbook." If you choose either of these options, the macro is associated with only one workbook and is not accessible to other workbooks.
- Enter an optional Description for this macro. You have the option of entering some text
describing what the macro does or when it is to be used.
- Click OK. The macro recorder is now running and will record all of your keystrokes.
- Back in the spreadsheet, in cell A1, enter your name as you wish to record it in this macro, leaving a space between each word. In my spreadsheet, I have entered "My First Macro" in cell A1.
- Press enter when you have finished entering your name. The cellpointer moves to the cell beneath the one where you entered your name (in this case, A2).
- Click the Stop Recording option on the Developer ribbon. The macro is now recorded.