Sub topic 7
Use Checkboxes as a Validated Input
This chapter assumes you can select cell ranges, enter basic formulas, and tell relative references (A2) from absolute ones ($A$2). It also assumes you have already built a drop-down from the Data validation dialog. A checkbox is a validation rule with only two allowed values. Once you see that, you can predict how checkboxes behave when you copy, paste, count or script them.
What a checkbox is in Sheets
A checkbox is a cell with a data validation rule that allows exactly two values. By default these are TRUE (checked) and FALSE (unchecked). The cell displays a clickable box in place of the text.
The rule lives in the same place as a drop-down rule. This means that:
- The cell holds a real value. A checked box is the Boolean
TRUE, and an unchecked box is the BooleanFALSE. - The rule can be edited, copied and removed like any other validation rule.
- Typing
TRUEorFALSEinto the cell has the same effect as clicking the box. - Any other typed value is handled by the rule's invalid-input setting, as described in the earlier chapter on rejecting input versus showing a warning.
You can insert checkboxes in two ways:
- Select the cells, then choose Insert > Checkbox.
- Select the cells, open Data > Data validation, add a rule, and choose Checkbox as the criteria.
Both routes create the same kind of rule. The Data validation route also exposes the options covered below.
Custom checked and unchecked values
The Data validation dialog lets you replace TRUE and FALSE with your own values. Choose Use custom cell values, then fill in one value for checked and one for unchecked.
For example, a review column might use Approved for checked and Pending for unchecked. The cell shows a checkbox, but the stored value is the text. Formulas must then compare against that text:
=COUNTIF(D2:D100, "Approved")If you leave the unchecked value blank, an unchecked box stores an empty cell. That is useful when you want blank rows to stay blank, and it makes COUNTA count only the checked rows.
| Setting | Checked stores | Unchecked stores | Typical use |
|---|---|---|---|
| Default | `TRUE` | `FALSE` | Simple task lists, formulas using Booleans |
| Custom text | `Approved` | `Pending` | Exported data that must contain readable words |
| Custom number | `1` | `0` | Sums and weighted scores |
| Custom with blank unchecked | `Yes` | (empty) | Columns where empty should mean "not answered" |
The custom values are part of the rule, not the cell. If you change them later, existing cells do not convert themselves. A cell that stores TRUE under a rule that now expects Approved is treated as invalid input.
Worked example: a task list
Set up a small sheet. Column A holds task names and column B holds checkboxes.
- Enter a header
TaskinA1andDoneinB1. - Type a few task names in
A2:A6. - Select
B2:B6and choose Insert > Checkbox. - In
D1, enter this formula to count finished tasks:
=COUNTIF(B2:B6, TRUE)- In
D2, show progress as a percentage:
=COUNTIF(B2:B6, TRUE) / COUNTA(A2:A6)Format D2 as a percentage. Each click on a box changes the count immediately, because the cell value changes.
You can also use the checkbox as a condition in a formula:
=IF(B2, "Finished", "Open")B2 alone works as the condition because it is already a Boolean. Writing B2=TRUE also works but adds nothing.
This works only with default values. With custom values such as Approved, IF(B2, ...) fails, because the text Approved is not a Boolean. Compare explicitly instead:
=IF(B2="Approved", "Finished", "Open")Checkboxes drive other features
A checkbox is often a switch for something else. Three common patterns follow.
Conditional formatting
Select A2:B6, choose Format > Conditional formatting, and set the rule to Custom formula is:
=$B2=TRUEThen pick a grey fill or strikethrough text. The $B locks the column, so every cell in the row checks column B. The 2 is relative, so each row checks its own checkbox. Without the $, the rule would check a different column for each cell in the range and the formatting would look random.
Filtering
A checkbox column can be filtered like any other column. Create a filter, open the column's filter menu, and choose Filter by values. The two values appear as TRUE and FALSE, or as your custom values.
Master checkbox
You can build a "select all" box. Put a checkbox in B1 and use a formula in the rows below that mirrors it:
=$B$1Rows with this formula follow the master box. They cannot be clicked independently unless you replace the formula with a plain value. Clicking a cell that holds a formula usually overwrites it with TRUE or FALSE, which breaks the link for that row. Plan for that, or keep the mirrored cells in a separate column.
Where checkboxes sit in the validation model
The concept graph for this tutorial treats checkboxes as a direct child of the validation basics. They do not depend on the drop-down chapters. They do share the same machinery, and that explains several behaviors.
Two consequences follow from this flow.
- A click always produces a valid value, because it toggles between the two stored values. Only typing and pasting can create invalid input.
- Whether a bad typed value is rejected or kept with a warning depends on the invalid-input setting, the same one drop-downs use.
Copying, pasting and clearing
Checkboxes move with the same rules as other validation.
- Copy and paste carries both the value and the rule. Pasting a checked box into other cells creates checked boxes there.
- Paste special > Data validation only copies the rule without changing the values. Use it to turn a column of ordinary cells into checkboxes while keeping their contents. Cells whose contents do not match the two allowed values are then flagged as invalid.
- Paste special > Values only copies the stored value but not the rule. The target cells show the word
TRUEorFALSEand no box. - Delete (the key) on a selected checkbox range clears the value but keeps the rule. The box remains and shows unchecked, or empty with a blank unchecked value.
- Remove validation in the Data validation dialog deletes the rule. The cell keeps its value and shows the text
TRUEorFALSEinstead of a box.
The last point surprises many users. If a sheet suddenly shows TRUE and FALSE where boxes used to be, something removed the rule, often a paste of values or a cleared validation.
Selecting several boxes at once
To check or uncheck many boxes at once, select the range and press the space bar. The first box in the selection decides the direction: if it is unchecked, all become checked, and the reverse. This is faster than clicking each box, and it works without any formula.
Clicking a box inside a selected range toggles only that one box in some situations, and the whole selection in others. If you want to change a single box, click an unselected cell first, then click the box.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Boxes turned into the words `TRUE` and `FALSE` | The validation rule was removed or overwritten by a values-only paste | Reapply **Insert > Checkbox** to the range |
| Red corner flag on a box | The cell holds a value that is not one of the two allowed values | Set it to a valid value, or edit the rule's custom values |
| `IF(B2, ...)` always returns the false branch | The box uses custom values, so the cell holds text and not a Boolean | Compare against the custom checked value |
| Count formula returns 0 | `COUNTIF(B2:B6, TRUE)` is used on a column with custom values such as `1` and `0` | Count the custom value instead, for example `COUNTIF(B2:B6, 1)` |
| Mirrored boxes stop following the master | A click overwrote the mirroring formula | Restore the formula or keep the mirrored values in a separate column |
| Blank rows count as unchecked | The count uses `COUNTIF(range, FALSE)` over a range that includes cells without boxes | Count only the checked values, or limit the range to cells that have boxes |
The last row deserves a note. An empty cell is not FALSE. A formula that counts FALSE values counts only cells that actually hold FALSE, so it depends on every row having a box.
Limits to keep in mind
Checkboxes inherit the limits of all validation, which a later chapter covers in full. Three apply here.
- Pasting ordinary values over a checkbox range removes the rule from those cells, so a checkbox does not protect against paste.
- Existing data is not checked when you add a rule. Cells that already hold other values are flagged only after the rule is applied, and they are not changed.
- A checkbox stores a value, not a person. It does not record who ticked it or when. If you need a timestamp, you need a script or the sheet's version history.
Setting checkboxes with Apps Script
The same rule can be created in Apps Script. The requireCheckbox builder method creates the default TRUE and FALSE rule. Passing a value makes it a custom checkbox.
function addDoneCheckboxes() {
const sheet = SpreadsheetApp.getActiveSheet();
const rule = SpreadsheetApp.newDataValidation()
.requireCheckbox()
.build();
sheet.getRange('B2:B6').setDataValidation(rule);
}
function addApprovalCheckboxes() {
const sheet = SpreadsheetApp.getActiveSheet();
const rule = SpreadsheetApp.newDataValidation()
.requireCheckbox('Approved', 'Pending')
.build();
sheet.getRange('D2:D100').setDataValidation(rule);
}The first function creates default boxes in B2:B6. The second creates boxes whose checked value is Approved and unchecked value is Pending. Removing the rule works as it does for other rules, with clearDataValidations(). After that call, the cells keep their values and lose the box.
Summary of decisions
Choose default TRUE and FALSE when formulas and conditional formatting will use the box directly. Choose custom values when the data leaves the sheet and must be readable, or when numbers are needed for sums. Leave unchecked blank when empty should mean "no answer yet."
Exercise
A column of checkboxes uses custom values: checked is Approved, unchecked is Pending. A teammate writes =IF(D2, "Ship", "Hold") and every row returns an error or the wrong branch. Explain why, then write a formula that works and a formula that counts the approved rows in D2:D100.
Show answer
With custom values, the cell holds the text Approved or Pending, not a Boolean, so IF(D2, ...) has no valid Boolean condition to test. Compare against the checked value instead: =IF(D2="Approved", "Ship", "Hold"). To count approved rows, use =COUNTIF(D2:D100, "Approved").
Exercise
You select a column of checkboxes and use Paste special > Values only to paste values copied from another sheet. The boxes disappear and the cells show the words TRUE and FALSE. What happened, and how do you restore the boxes without losing the values?
Show answer
The values-only paste replaced the cell contents and removed the validation rule, so the cells became ordinary Boolean values shown as text. Select the range again and choose Insert > Checkbox. The existing TRUE and FALSE values match the default allowed values, so they are kept and display as checked and unchecked boxes.