Microsoft® Excel 2007: record a simple macro and edit it in VBA
If you need to perform the exact same steps multiple times, use an Excel macro.
With an Excel macro, it's best if you can record the steps efficiently with no extra actions. However, if you need to make some changes to a macro, you have the powerful VBA (Visual Basic for Applications) language available in the built-in Visual Basic editor. Just open the editor and edit your macro as needed.
In this demonstration, you'll learn how to edit a macro in the VBA editor.
First, let's record a simple macro and make an intentional error in it. Then we'll edit out the error in VBA.
On the Developer tab, click Record Macro.
Type a name for the macro.
Click OK.
Click the Home tab.
Click the Bold button.
Click OK.
Click the Italic button.
Clicking the Italic button is an intentional error for this demonstration.
Click OK.
Click the Stop Recording button on the status bar.
Click OK.
Now let's edit out the error in VBA.
Click the Developer tab.
Click the Macros button.
In the Macro dialog box, select the macro to edit.
Click Edit.
This macro is stored in the Personal Macro Workbook, which is hidden by default. You must unhide it before you can edit the macro.
Click OK.
Click Cancel.
Click the View tab.
Click the Unhide button.
Select the workbook to unhide, and then click OK.
Now the Personal Macro Workbook is visible.
Click the Developer tab.
Click the Macros button.
Select the macro to edit.
Click Edit.
The VBA editor window opens.
Select the line that refers to the Italic button.
Press Delete.
Click the Save button.
Close the editor window.
Now we'll test the macro by typing some text in a cell and applying the macro to it.
Click the Macros button.
Select the macro to run.
Click Run.
The macro applies bold formatting, but not italic.
In this demonstration, you learned how to edit a macro using the VBA language in Excel 2007's built-in VBA editor.