Editing and Deleting Macros in Microsoft Excel

Editing and Deleting Macros in Microsoft Excel

Editing a Macro

If you need to make simple changes to a macro, such as inserting text or deleting a command, such as a specific format applied to a cell, you can edit the macro. You edit a macro in the Visual Basic Editor, shown in Figure 2-6. The elements of the Visual Basic Editor are described in the table below.

The Project Explorer, Properties window, and Code window all appear when you open the Visual Basic Editor. Since you won’t need the Properties window while performing simple editing, you can close the Properties window, and then expand the Project Explorer to view more of its window.

Each open workbook in Excel has a project associated with it in the Project Explorer. Navigating the Project Explorer is similar to navigating Windows Explorer, in that they both have hierarchical structures. The code for a macro is stored in a module, which is simply a holding place for the code, just as a worksheet is a holding place for data in cells. Double-clicking a module in Project Explorer displays the module’s code in the Code window. Editing Visual Basic code is similar to editing text in a word processing program.

For more details of Macro and VBA Excel training in Los Angeles call us on 888.815.0604. Our classes are hands-on and instructor-led. Beginner, Intermediate and Advanced Excel classes are also available.

Figure 2-6: The Visual Basic Editor

Figure 2-6: The Visual Basic Editor

Element Description
Project Explorer Contains projects that store the Visual Basic code for each open workbook. Each project can contain folders for objects (such as the worksheets in the workbook), forms, references, and modules. You select a module to view its code, copy modules to other open workbooks, and delete modules.
Code window Displays the Visual Basic code for the selected module in a project.
Properties window Displays specific characteristics of an object, such as the name of the object, or the standard width of the columns.
Standard (macro) toolbar Displays the basic tools needed to use the Visual Basic Editor.
Object box Contains a drop-down list from which to select the desired object whose code you want to view in the Code window. If General appears in the Object box, all the code for the macros associated with the selected module appears in the Code window.
Procedure box Contains a drop-down list from which to select a macro to display the macro’s code in the Code window.

Steps to Edit a Macro

To display the Visual Basic Editor:
  1. In the Code group on the Developer tab, click the Visual Basic button.
To edit a macro:
  1. Display the Visual Basic Editor.
  2. From the Tools menu, choose Macros.
  3. In the Macros dialog box, from the Macros In drop-down list, select the project containing the macro you want to edit.
  4. In the Macro Name list box, select the desired macro.
  5. Choose Edit.
  6. In the Code window, make the desired edits.
  7. Close the Macros dialog box.
To close the Visual Basic Editor:
  1. From the File menu, choose Close and Return to Microsoft Excel.

Also see how to record a Macro.

Deleting a Macro

If you no longer need a macro, you can delete it. Deleting unwanted macros makes it easier to view macros in the Code window in the Visual Basic Editor as well as view macros in the Macro dialog box.

You can delete a macro in an open workbook using the Macro dialog box or the Visual Basic Editor. If you want to delete a macro in the Personal Macro Workbook using the Macro dialog box, you must first unhide the Personal Macro Workbook. A benefit of using the Visual Basic Editor is that you can delete any macro in any open workbook or the Personal Macro Workbook, without unhiding it.

Steps to Delete a Macro

Macro dialog box method:
  1. Locate the Code group in the Developer tab on the Ribbon
  2. In the Code group on the Developer tab, click the Macros button.
  3. In the Macro dialog box, in the Macro Name list box, select the macro you want to delete.
  4. Choose Delete.
  5. In the message box that appears, choose Yes.
Visual Basic Editor method:
  1. Locate the Code group in the Developer tab on the Ribbon.
  2. In the Code group on the Developer tab, click the Visual Basic button.
  3. From the Tools menu, choose Macros.
  4. In the Macros dialog box, from the Macros In drop-down list, select the project containing the macro you want to delete.
  5. In the Macro Name list box, select the desired macro.
  6. Choose Delete.
  7. From the File menu, choose Close and Return to Microsoft Excel.
 

Onsite Excel training

Through our network of local trainers we deliver onsite group Microsoft Excel training right across the country. View our Excel training testimonials or obtain a quote for a customized Excel class.