Sub topic 11
Know what validation does not protect against
This chapter assumes you can select ranges, write basic formulas, use absolute and relative references such as $A$2, and refer to another sheet. It also assumes you have built at least one drop-down and one custom formula rule from the earlier chapters.
Data validation in Google Sheets checks values when a person types or picks them into a cell. It does not guarantee that every value in the sheet is valid. Several ordinary actions skip the check, and a few of them silently remove the rule. This chapter lists those gaps, explains why they exist, and shows how to detect and reduce them.
What validation actually checks
A validation rule is attached to cells as a property, like a number format. It is evaluated at one moment: when a user enters a value by typing, picking from a drop-down, or ticking a checkbox. If the entry fails and the rule is set to reject input, Sheets refuses it. If the rule is set to show a warning, Sheets accepts the entry and flags it.
Nothing keeps checking afterwards. The rule does not scan the sheet, does not recheck when its source list changes, and does not apply to values that arrive by another route. That makes the rule an entry-time guard, not a data-integrity guarantee.
Paste is the largest gap
Paste is where most validated sheets break. There are three distinct behaviors, and it helps to keep them apart.
Normal paste replaces the rule
When you copy a cell inside Sheets and paste it with Ctrl+V (Cmd+V on a Mac), Sheets pastes everything about the source cell: value, formatting, and its validation. If the source cell has no rule, the destination loses its rule. If the source has a different rule, the destination gets that one.
A common failure looks like this. A column of statuses has a three-item drop-down. Someone copies a status from a plain, unvalidated cell elsewhere and pastes it over the middle of the column. That cell now accepts anything, and no error appears.
Paste values only skips the check
Paste special > Values only keeps the destination's rule, but it does not run the rule against the pasted values. The values land in the cells whether or not they would have been accepted when typed. Content copied from another application, such as an email or a web page, behaves the same way. The value is placed in the cell without validation.
Pasted invalid values are flagged, not blocked
A cell holding a value that fails its rule gets a small marker in its corner, and hovering over it shows the validation message. The marker tells you something is wrong, but it does not undo the paste, and it is easy to miss in a long column.
The following table summarizes the paste options.
| Action | Value checked? | Destination rule after |
|---|---|---|
| Type or pick from the drop-down | Yes | Unchanged |
| Ctrl+V from a cell with no rule | No | Removed |
| Ctrl+V from a cell with a different rule | No | Replaced by the source's rule |
| Paste special > Values only | No | Unchanged |
| Paste from outside Sheets | No | Unchanged |
| Paste special > Data validation only | Not applicable | Replaced by the source's rule |
| Delete key | Not applicable | Unchanged, cell becomes empty |
Existing data is not rechecked
When you apply a rule to a range that already contains data, Sheets does not change or remove the existing values. Entries that fail the rule are marked, and everything else is left alone. This has two consequences.
- You cannot clean up a messy column just by adding a rule. You still have to find and fix the bad values yourself.
- If you later change a rule, for example by removing "Blocked" from a status list, cells that already contain "Blocked" stay as they are. They become flagged, but any formulas that read them keep working with the old value.
The same applies to range-based drop-downs. When someone edits an item in the source range, cells that used the old text are not updated. They simply no longer match.
Other routes that skip validation
Several other mechanisms write values without going through the rule.
- Formulas. Validation checks entered input. If a validated cell contains a formula such as
=IF(D2>10,"Done","Blocked"), the result is not tested against the rule. - Apps Script and the Sheets API. Methods such as
setValueandsetValueswrite directly. A script can place any value in a cell regardless of the rule. - Imports and copies. Data pulled in with
IMPORTRANGEor similar functions is a formula result, so it is not validated. Copying a whole sheet keeps its rules, but the copy then has its own rules that no longer follow changes to the original. - Drag and move. Moving cells by dragging or with cut and paste takes the validation with them and leaves the original location without it.
- Clearing a cell. Pressing Delete empties a cell and is always allowed. Validation does not make a cell mandatory. If a field must not be blank, validation alone cannot enforce that.
- Structure changes. Inserting rows inside a validated range extends the rule to them. Inserting a row just below the range does not. Rows added at the bottom of a table often have no rule.
Anyone with edit access can change the rules
Validation is not access control. A user with edit access can open Data > Data validation, change the rule, or delete it. For data that must stay consistent, such as a lookup column that formulas depend on, protect the range.
- Select the range, for example C2:C100.
- Choose Data > Protect sheets and ranges.
- Add a description, then set permissions so that only chosen people can edit.
Protection stops unauthorized edits entirely, so use it for the lists and rules, not for the input cells that users must fill in. For input cells, the realistic goal is to catch mistakes, not to stop determined users.
Detecting invalid data after the fact
Because validation can be bypassed, build a check that reads the data and reports problems. This works for any route, including paste and scripts.
An audit column
For a status column in C that must match a list in Lists!A2:A10, put this in D2 and fill it down:
=IF(C2="", "", IF(SUMPRODUCT(--EXACT(C2, Lists!$A$2:$A$10))>0, "OK", "Invalid"))EXACT compares text with case sensitivity and treats wildcard characters literally. Functions such as COUNTIF and MATCH ignore case and give special meaning to * and ?, so they can pass values that the drop-down would not have accepted. If a looser check is fine for your data, COUNTIF is shorter.
For rules that do not depend on a list, reuse the same expression as the rule. For the duplicate rule from the custom formula chapter, an audit cell can read:
=IF(A2="", "", IF(COUNTIF($A$2:$A$100, A2)=1, "OK", "Duplicate"))Highlight the problems
Add a conditional formatting rule to C2:C100 with the custom formula =$D2="Invalid" and a red fill. Pointing the rule at the audit column avoids referring to another sheet from the formatting rule.
Count and filter
Put a summary somewhere visible, for example =COUNTIF(D2:D100, "Invalid"), so the number of problems is always on screen. To find the offending rows, filter column D for "Invalid". You can also add a filter view so others can do it without changing the shared view.
Catching bad input with Apps Script
An installable or simple onEdit trigger fires after a user edits cells, including after a paste. It can check the new values and mark any that are wrong. This does not prevent the bad value, but it flags it immediately in a way the user cannot miss. The following script highlights any value in column C of the sheet named Tasks that is not in the allowed list, and clears the highlight when the value is corrected.
const ALLOWED_STATUSES = ['Not started', 'In progress', 'Done'];
const STATUS_COLUMN = 3;
function onEdit(e) {
const range = e.range;
const sheet = range.getSheet();
if (sheet.getName() !== 'Tasks') return;
if (range.getColumn() > STATUS_COLUMN || range.getLastColumn() < STATUS_COLUMN) return;
const firstRow = Math.max(range.getRow(), 2);
const lastRow = range.getLastRow();
if (lastRow < firstRow) return;
const cells = sheet.getRange(firstRow, STATUS_COLUMN, lastRow - firstRow + 1, 1);
const backgrounds = cells.getValues().map(function (row) {
const value = row[0];
const isValid = value === '' || ALLOWED_STATUSES.indexOf(value) !== -1;
return [isValid ? null : '#f4c7c3'];
});
cells.setBackgrounds(backgrounds);
}Three details matter here.
- The script checks the whole edited range, not only
e.value. For a multi-cell paste,e.valueis not set to a single value, so checkinge.rangeis what makes the paste case work. - Passing
nulltosetBackgroundsresets a cell to its default background. That removes the highlight once the value is fixed. - The simple
onEdittrigger runs only for edits made by a person in the editor. Changes made by other scripts or by the API do not fire it, so it does not cover those routes.
Choosing a defense
No single measure covers every gap, so match the defense to the cost of bad data.
| Situation | Reasonable approach |
|---|---|
| Personal tracker, one user | Validation alone |
| Shared sheet, occasional mistakes | Validation plus an audit column and red highlighting |
| Lookup lists and rule ranges that formulas depend on | Protected range, editors limited |
| Many contributors who paste often | Validation, audit check, and an `onEdit` flag |
| Data that must be correct and complete | Collect it through a form or an application that enforces the rules, and use the sheet for reporting |
Common errors
- Assuming reject mode blocks everything. It blocks typed and picked entries only. Pasted values still arrive.
- Adding a rule and treating old data as clean. Existing values stay in place. Run the audit column first.
- Using
COUNTIFas a strict list check. It ignores case and treats*and?as wildcards, so it can accept text that is not an exact list item. - Forgetting the rows below the range. A rule covering C2:C100 does not apply to row 101. Apply the rule to a larger range, or to the entire column below the header, if the table grows.
- Protecting the input cells themselves. Protection that blocks editing also blocks the people who need to enter data. Protect the lists and the rules instead.
Exercise
A status column C2:C100 has a three-item drop-down set to reject invalid input. A colleague copies a cell from another sheet that contains the text "Waiting" and pastes it into C10 with Ctrl+V. The source cell has no validation. What does C10 contain afterward, and what should you do to detect this kind of problem across the whole column?
Show answer
C10 contains "Waiting", and the drop-down rule on C10 is gone because a normal paste copies the source cell's validation settings, which here means none. The rule was never run against the pasted text. To detect such cases, add an audit column that compares each status against the list, for example =IF(C2="","",IF(SUMPRODUCT(--EXACT(C2,Lists!$A$2:$A$10))>0,"OK","Invalid")), highlight rows marked "Invalid", and count them with COUNTIF. Then reapply the rule to C2:C100 to restore the drop-down.
Exercise
You add a "reject input" list rule to a column that already contains the values "done" (lowercase) and "Finished", while the list items are "Not started", "In progress" and "Done". Does Sheets change or remove the existing values? How would you list the problem rows?
Show answer
No. Existing values are left unchanged, and Sheets only marks the cells that fail the rule. Whether lowercase "done" counts as a match depends on how the rule compares text, so do not rely on that. To list the problem rows, use an audit column with the EXACT-based formula, which treats "done" and "Done" as different, then filter the audit column for "Invalid". "Finished" is never in the list and is always flagged.
Exercise
Why does the onEdit script in this chapter read e.range instead of only e.value, and which kinds of writes will it still miss?
Show answer
A paste can change many cells at once, and e.value is only meaningful for a single-cell edit. Reading e.range lets the script check every pasted row in column C. The simple onEdit trigger does not fire for changes made by other scripts, API calls, or formula results, so it misses those writes.