Written by Allen Wyatt (last updated July 26, 2021)
This tip applies to Excel 2007, 2010, 2013, and 2016
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.
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!
List boxes can be a great tool for getting input from users of your worksheets. This tip describes what list boxes are ...
Discover MoreLots of people prefer to enter information directly into Excel, but there is another way that may be helpful: Using data ...
Discover MoreRadio buttons are great for some data collection purposes. They may not be that great for some purposes, however, for the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2017-03-28 07:42:59
Mike
This almost worked. 1st check updated cell A1 but the second Uncheck caused a macro error.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments