Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Editing Macros.

Editing Macros

by Allen Wyatt
(last updated March 28, 2015)

2

Taking a look at the programming code used in a macro (either ones you have recorded or macros created by others) is a great way to help you understand how the macro is put together and how it works. You can do this examination, and make changes to your macros, by editing them. To edit a macro you first need to display the Macro dialog box. The easiest way to do this is to simply press Alt+F8. (See Figure 1.)

Figure 1. The Macro dialog box.

In the list of available macros you should choose the macro you want to edit. When you have selected one, you can click on the Edit button and the VBA Editor is displayed with the selected macro loaded and ready to edit.

Once your macro is displayed, you can make changes to it as desired. You use many of the same editing functions you use when making changes to a regular worksheet. Unless you fully understand the consequences of your changes, it is typically best to stick to recording simple macros. If you feel adventurous, however, there is nothing wrong with making changes to your macros to see what they will do. If you do so, it is a good idea to keep these tips in mind:

  • As you are developing and testing macros, always use copies of your data. Keep the original data stored in a safe place.
  • Keep a good macro language function reference or command reference close by.
  • Test often as you make changes. Don't make all your changes at once and then expect to perform one test and have everything work. Unfortunately, life is not that simple.

If you keep these tips in mind, there is very little chance that you will hurt anything. In fact, your chances of learning more about Excel and macro programming are much greater than the risk of damaging any data. Give it a try!

When you have finished making changes to your macro, you should close the VBA Editor. Closing the VBA Editor is done in the same manner as when you close any other Windows program—simply double-click on the Close icon in the upper-right corner of the window.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9753) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Editing Macros.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Setting Embellishment Spacing in the Equation Editor

The equation editor is a great tool for adding mathematical equations into your document. The placement of many elements of ...

Discover More

Filtering for Comments

Excel makes it easy to filter a data table based on various values in that table. It isn't so easy to filter according to ...

Discover More

Extra Spaces after Inserting a Building Block

Building blocks are a great tool for inserting standard information in your documents. It is also possible, however, to get ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Calculating Only the Active Workbook

When you enter information into a workbook, Excel automatically recalculates every worksheet in every open workbook on your ...

Discover More

Renaming a Macro

Got a macro that doesn't have quite the right name? You can rename the macro by following these simple steps.

Discover More

Removing All Macros

Macros are stored as part of a workbook so that they are always available when you have the workbook open. If you want to get ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine more than 8?

2015-04-23 23:32:28

Dennis Costello

Something else to keep in mind is that the Macro Recorder creates VBA code that is correct but utilizes bad - or at least "unfortunate" programming practices.

In particular, the sequence:
<range>.Select
Selection.<action>

which the Recorder generates pretty much by default, is potentially a lot more expensive in execution (not to mention being harder to read, edit, and maintain) than the simpler:
<range>.<action>

You will similarly see
<range>.Activate
ActiveSheet.<action>

(or ActiveWorkbook.<action>) in code produced by the Recorder.

Despite this, I agree with Allen that the Recorder is a great way to begin learning VBA coding, or how to capture in VBA some Excel task that you haven't done in VBA before. But you should follow it up with the Excel Object Model Reference and/or Visual Basic for Applications Language Reference.


2015-03-31 08:22:25

balthamossa2b

Or even faster: Alt + F11 to go straight to the editor. Then dig around your Modules to find the macro you want.

With the bonus that yu can see the Worksheet and Workbook macros, which don't appear on the Dialog Box. Nor Functions.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.