Macros Run Fine Individually, but Not Collectively

by Allen Wyatt
(last updated June 3, 2016)


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 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 the 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.

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

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


Using the Copy or Move Text Keys

Most people use the Clipboard to copy and move text in Word. Before the Clipboard, Word used F2 to move text and Shift+F2 ...

Discover More

Understanding Background Saving

Word has the capability to save your work, in the background, while you continue to edit your documents. This tip ...

Discover More

Loading Unwanted Files at Startup

Imagine how painful it would be if every time you started Excel it tried to load all the files in your root directory? ...

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)

Determining If a Number is Odd or Even

If you need to know whether a particular value is odd or even, you can use this simple formula. Designed to be used in a ...

Discover More

Converting Strings to Numbers

When working with data in a macro, there are two broad categories you can manipulate: numbers and text. Sometimes you ...

Discover More

Disabling Shift Key Use when Opening a Workbook

Open up a workbook, and Excel normally runs the macros associated with that workbook. You can disable the automatic ...

Discover More

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

View most recent newsletter.


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

2013-11-12 09:18:28


I don't have a problem with the ActiveWorkbook and Selection objects. If your macros run against multiple worksheets or workbooks then you should always initialize those objects before using them and never assume their values.

2013-11-11 08:17:09


I think the only correct answer to this question is "show me your macros, the sheets you run them on, and what line is bringing the error".

There's really no way to tell why the problem is occurring from such a generic problem statement, though this is yet another argument against using the ActiveWorkbook and Selection objects.

2013-11-09 20:54:53

Chuck Trese

fyi, I can say from experience, Excel does properly wait for one macro to finish before it executes the next. A batch file is usually different because you are generally kicking off different (independent) applications that are designed to run in parallel. But since this is all within Excel, it behaves 100% linear. The only exception I'm aware of is if you launch a modeless form, you could get things out of order from what you intended.

2013-11-09 20:28:06

Chuck Trese

I have a Macro-macro, a "RunAll", of sorts. Aware that many of my macros do their work on the ActiveSheet, I preface each sub-macro with a Sheetx.Activate command. (In my case, the macros called are button-clicks on the respective sheets.)

Something like this:
Call Application.Run("'" & ThisWorkbook.Name & "'!" & "Sheet5.PTCViewShowTypeALL_Click")
Call Application.Run("'" & ThisWorkbook.Name & "'!" & "Sheet5.PTCViewGraphStandard_Click")
Call Application.Run("'" & ThisWorkbook.Name & "'!" & "Sheet6.PTCViewShowTypeALL_Click")
Call Application.Run("'" & ThisWorkbook.Name & "'!" & "Sheet6.PTCViewGraphStandard_Click")

It may not be the full solution to Guillerom's problem, but it has kept me out of trouble.

2013-11-09 18:55:10


If the individual macros are run in the order that they are specified in the RunAll macro and they run successfully, then I do not think this explanation is valid.

I do not know the rules for running macros within a macro, but is it possible that later macros are not waiting for the earlier ones to finish before starting? This could be tested by putting in a long time delay after each macro in the RunAll macro, perhaps by doing putting in a loop to execute an appropriate number of times before proceeding.

I know that in a batch file successive executions do not wait for the earlier ones to complete before starting.

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

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.