Macros Run Fine Individually, but Not Collectively

Written by Allen Wyatt (last updated March 2, 2019)
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

Getting Rid of Alphabetic Characters

When you need to get rid of characters in the middle of a cell value, the best way to do it is through the use of macros. ...

Discover More

Monday's Date on Friday's Report

Automatically putting today's date at the top of a report is easy. Putting a different date, automatically, can be more ...

Discover More

Relative Worksheet References

Copy a formula from one place to another and Excel helpfully adjusts the cell references within the formula. That is, it ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Copying Worksheet Code Automatically

When creating a workbook to be used by others, you may want any worksheets they add to the workbook to contain some ...

Discover More

Unprotecting Groups of Worksheets

Unprotecting a single worksheet is relatively easy. Unprotecting a whole lot of worksheets is harder. Here's how you can ...

Discover More

Triggering an Event when a Worksheet is Deactivated

One way you can use macros in a workbook is to have them automatically triggered when certain events take place. Here's ...

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 1 + 1?

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.