Running a Macro while in Edit Mode

Written by Allen Wyatt (last updated August 30, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Brendon created a very simple macro to save the current workbook and close it. He then added an icon to the Quick Access Toolbar (QAT) for the macro. The macro works well if the user isn't in Edit mode in the worksheet. If, for example, a user enters data in a cell but never presses Enter or doesn't select a different cell, then the macro won't run. It's like the QAT icon is greyed out. Brendon wonders how he can get around this and force the macro to run.

Brendon has run up against one of the fundamental limitations of Excel—you cannot run a macro while you are in Edit mode. In fact, there are many things you cannot do while you are in Edit mode—for instance, most of the ribbon tools aren't available, and most shortcut keys won't work. Excel limits what you can do to only those things dealing with editing the cell contents.

The solution is to get out of Edit mode before running the macro. One easy way to do this is to (as Brendon points out) simply press Enter or press Tab to move to a different cell.

If training the user to do that is a bit too much, then you might place your macro somewhere else besides the QAT. The most effective approach would be to place a shape in your workbook and then attach the macro to that shape. (How to actually do this is a bit beyond the scope of this particular tip.) The shape—which you would need to design in a graphics program—could look a "button" that says something like "Click here to save and exit." The user, in clicking on the shape, would automatically leave Edit mode, which means the macro attached to the shape would run.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13736) 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

Inserting a Document's Path

You can use the FILENAME field to insert a document's filename and, optionally, the path to that filename. However, if ...

Discover More

Animated Menus

The menus used in Excel can be animated in several different ways. All it takes is a quick change to the Excel options.

Discover More

Adding Caption Labels

When using the captioning capabilities of Word, you aren't limited to the three default caption labels provided in the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Swapping Two Strings

Strings are used quite frequently in macros. You may want to swap the contents of two string variables, and you can do so ...

Discover More

Storing Macros in Templates

How Excel uses templates is different than how Word uses templates. This tip looks at those differences and discusses ...

Discover More

Recovering Macros from Corrupted Workbooks

Workbooks get corrupted from time to time; that's a fact of life in an Excel world. If those corrupted workbooks contain ...

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 less than 9?

2020-02-08 15:25:19

John Mann

While it's possible to use a graphics programme to design a shape to be used as a button, it's not necessary (a tleast not in Excel 10).

On the Ribon, click "Insert" then "Shapes" Choose a shape you like, edit it in the way you desire, and the wished for text. Then right click the shape and from the context menu select "Assign Macro..." From now on you can either add an existing macro or create a new one.


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.