Protecting Formulas in Control-Linked Cells

by Allen Wyatt
(last updated March 25, 2017)

1

Michael has a form control (a check box) linked to cell A1. He can place a formula into cell A1 that resolves to True or False, and the check box reflects that result. However, if someone clicks on the check box to change it, the formula in cell A1 is overwritten by an explicit True or False. Michael needs the formula in cell A1 to control the check box, but he also needs the user to be able to toggle the check box without overwriting the formula. He wonders if this is possible.

In short, this is not possible. Microsoft intended check boxes to control the value in a cell, and then you could reference that cell in other formulas. They never intended for the linked cells to contain formulas.

One thing you could try, if you desire, is to create a macro that monitors a cell and, if it changes, update a different cell. For instance, you could tie your check box to a different cell (such as cell B1), so that the formula in cell A1 isn't affected when the check box is used. You an then create an event handler macro that examines whatever is in cell A1, and if it changes, then the macro modifies what is in cell B1. This modification in cell B1 will then trigger the change in the check box.

Another macro-based approach is to use a macro to write a formula into cell A1. This is a simple example of such a macro:

Sub CheckBoxState()
    Range("A1").Formula = "=IF(" & Range("A1") & _
      ",""CHECKED"",""NOT CHECKED"")"
End Sub

If you assign this macro to the check box control, then when a person clicks the check box, two things happen. First, the state of the check box is written to cell A1, overwriting whatever is there. Second, the macro is executed, writing the formula back into cell A1. Note that the formula (as defined in this macro) takes into account the value that was just stored in cell A1. Thus, if the check box control writes True into cell A1, then the macro stuffs the following into the cell:

=IF(TRUE,"CHECKED","NOT CHECKED")

Click the check box again, the value stuffed into the cell changes to False, and the formula that is placed into the cell changes. Of course, you would need to modify the macro so that the formula it forces into cell A1 reflects the formula you really want there.

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

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

Printing Workbook Properties

Want to create a printed record of the properties associated with a workbook? There is no easy way to do it in Excel. ...

Discover More

Setting Column Width in a Macro

Does your macro need to change the width of some columns in a worksheet? Here's how to do it.

Discover More

Problems with TOC Styles

If you generate a table of contents for your document, there may be some unexpected surprises in the way the TOC appears. ...

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)

Independent Radio Buttons

Radio buttons are great for some data collection purposes. They may not be that great for some purposes, however, for the ...

Discover More

Using List Box Controls

List boxes can be a great tool for getting input from users of your worksheets. This tip describes what list boxes are ...

Discover More

Using Data Forms

Lots of people prefer to enter information directly into Excel, but there is another way that may be helpful: Using data ...

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 four more than 2?

2017-03-28 07:42:59

Mike

This almost worked. 1st check updated cell A1 but the second Uncheck caused a macro error.


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.