Protecting Formulas in Control-Linked Cells

Written by Allen Wyatt (last updated July 26, 2021)
This tip applies to Excel 2007, 2010, 2013, and 2016


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

Columns within Text Boxes

Text boxes are a common design element for some documents. If you want a text box to contain multiple columns, you are ...

Discover More

Hiding Columns Based on a Cell Value

Need to hide a given column based on the value in a particular cell? The easiest way to accomplish the task is to use a ...

Discover More

Resetting Character Formatting in a Macro

Shortcut keys are a great way to apply styles to text in a document. You can easily create a shortcut key assignment for ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

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

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