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

Why Should I Upgrade?

As new versions of software are released, users are perpetually faced with the decision of whether to upgrade their software ...

Discover More

Using the ABS Function

Need to find the absolute value of a number? That's where the ABS function comes into play.

Discover More

Drop Shadows for Tables

When adding borders and shading to a document's elements, Word allows you to quickly add drop shadows to paragraphs, text ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Automating the Importing of Macros

Macros are great when it comes to automating how you work with your workbooks. What if you want to fundamentally change the ...

Discover More

Macro for Month Name

Need to know how to generate a full month name based on a date? It's easy to do, as discussed in this tip.

Discover More

Making Common Functions Available to Others

When you use macros to create functions, you might want to share those functions with others—particularly if they ...

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 3 + 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.