Macros Run Fine Individually, but Not Collectively

Written by Allen Wyatt (last updated July 10, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Guillermo has a series of macros that he routinely runs, and when he runs each of them manually, they work fine. He tried to place all of the macros into a "RunAll" macro (so he only has to run one macro instead of six individual macros) and now one of them doesn't run properly. When he executes the RunAll macro, he gets an error that a cell is protected and read-only. However, there is no protection on the sheet, and if he runs the macros individually, he doesn't get the error.

It should go without saying that the macro that executes fine individually but not in conjunction with the others is encountering something that is causing it to not work right. Likely that means that a macro running before it is leaving the workbook in a different state than it would be in if you ran the macros individually.

For instance, if the misbehaving macro is the third in the series to run, check the first two macros to see what they are doing. Do they change the selected cells? Do they change the active worksheet? Do they change any conditions that the third macro expects? Any of these could cause the third macro to not function properly.

It is the second suggestion—about the active worksheet—that is the most likely scenario. When you run the macro individually, chances are good that you run it with a particular worksheet active. The other macros, though, may change the active worksheet to a different one, and that different worksheet may be the one that has protection applied to it.

The solution is to check each macro to make sure that it saves the locational information (worksheet, active cell, selected cells, etc.) before making any changes to any of those. With them saved, it is an easy matter to restore them at the end of the macro.

If that still doesn't do it, then you may need to do some debugging. In the "RunAll" macro, use the VBA Editor to establish a breakpoint on the line that calls the failing macro. You can then use the "Step Into" command to step into the macro and examine where the failure occurs. Pay particular attention to what worksheet and cells the macro is trying to change, and then see if you can figure out what is going on with the earlier macros to lead to that worksheet and cells. You can use either of the following lines in the Immediate window to see where you are:

? ActiveSheet.Name
? ActiveCell.Address

While tracking down these types of errors can be a challenge, the light at the end of the tunnel is that you will end up with a perfectly functioning "RunAll" macro that can save you a great deal of time.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12710) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

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

Clearing Everything Except Formulas

Need to get rid of everything in a worksheet except for your formulas? You can do it rather easily by applying the ideas ...

Discover More

Ignoring Smart Quotes when Comparing Text

When comparing two pieces of text, you may find that Word's smart quotes can mess up the comparison. Here's a quick way ...

Discover More

Macro Fails after Filter

When developing a macro that others may use, you might want to test it out to make sure it works properly if a filter is ...

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)

Using SUM In a Macro

Want to use a worksheet function (such as SUM) from within a macro? Here's how easy it is to accomplish the task.

Discover More

Running a Macro while in Edit Mode

Excel doesn't allow you to run a macro while editing the contents of a cell. The only solution is to get out of Edit ...

Discover More

Deleting VBA Code in a Copied Worksheet

VBA makes it easy to copy a worksheet from the current workbook into a brand-new workbook. You may want to delete some ...

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}] (all 7 characters, in the sequence shown) 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 two more than 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.