The first step of creating a macro is to plan the process you want
to automate. Computers today are quite fast, so adding an extra step
that doesn’t affect the outcome of a process doesn’t slow you down
noticeably, but leaving out a step means you will need to re-record your
macro. After you plan your process, you can create a macro by clicking
the View tab and then, in the Macros group, clicking the Macros arrow.
In the list that appears, click Record Macro. When you do, the Record
Macro dialog box opens.
After you type the name of your macro in the Macro Name
box, click OK. You can now perform the actions you want Excel to repeat
later; when you’re done, in the Macros list, click Stop Recording to add
your macro to the list of macros available in your workbook.
To modify an existing macro, you can simply delete the macro and
re-record it. Or if you just need to make a quick change, you can open
it in the Visual Basic Editor and add to or change the macro’s
instructions. To delete a macro, open the Macro dialog box, click the
macro you want to delete, and then click Delete.
See Also
For more information about using the Visual Basic Editor, press
Alt+F11 to display the Visual Basic Editor, and then press F1 to
display the Visual Basic Help dialog box.
In this exercise, you’ll record, edit, save, and run a macro that
removes the bold formatting from selected cells.
Open the
YearlySalesSummary_start workbook, click the Enable Content button on
the Message Bar (if necessary), and save the workbook as
YearlySalesSummary. Then follow the steps.
-
On the View tab, in the
Macros group, click the Macros arrow and then, in the list that
appears, click Record
Macro.
The Record Macro dialog box opens.
-
In the Macro name box,
delete the existing name, and then type RemoveHighlight.
-
Click OK.
The Record Macro dialog box closes.
-
Select the cell range C4:C7.
The text in these cells is currently bold.
-
On the Home tab, in the
Font group, click the Bold button.
-
On the View tab, in the
Macros list, click Stop Recording.
Excel stops recording the macro.
-
In the Macros list, click
View Macros.
The Macro dialog box opens.
-
In the Macro name area,
click RemoveHighlight, and then
click Edit.
The Visual Basic Editor starts.
-
Edit the line of code that currently reads Range(“C4:C7”). Select so that it reads
Range(“C3:C9”). Select.
This macro statement selects the cell range C3:C9, not
the incorrect range C4:C7.
-
On the Standard toolbar of
the Visual Basic Editor, click the Save button to save your change.
-
On the title bar of the Visual Basic Editor window, click the
Close button.
The Visual Basic Editor closes.
-
Select cells C3:C9, format
them as bold, and then click cell C9.
Excel formats the cells’ contents in bold.
-
In the Macros list, click
View Macros.
The Macro dialog box opens.
-
Click RemoveHighlight, and
then click Run.
The bold formatting is removed from cells C3:C9.
-
On the Quick Access Toolbar, click the Save button.
Excel saves your workbook.
Clean Up
Close the YearlySalesSummary workbook.