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

Counting with Formulas

When you need to count a number of cells based upon a single criteria, the standard function to use is COUNTIF. This tip ...

Discover More

Specifying the Number of MRU Files

MRU (most recently used) files can be a great help when you work with a given set of common workbooks. Excel allows you ...

Discover More

Disabling All Function Keys Except One

Disabling function keys is rather easy to do when you rely on the OnKey method in a macro. This tip looks at how you can ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

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

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

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 two more than 7?

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.