Sub topic 8
Apply, copy, edit and remove rules
This chapter covers how validation rules are attached to cells and how you manage them over time. It assumes you can select cells and ranges, enter values and basic formulas, and tell relative references such as A2 from absolute ones such as $A$2. You should also have built at least one drop-down from a typed list or a range, as covered in earlier chapters.
What a rule is attached to
A validation rule belongs to a range of cells, not to a value. The rule stores three things: the criteria (for example "Dropdown" with three items), what happens on invalid input (reject or warn), and optional help text. When you change a cell's content, the rule stays. When you delete the cell's content, the rule also stays.
This matters for every operation in this chapter. Copying, pasting, inserting rows and clearing all act on the rule as well as on the value, and each does so in a slightly different way.
Apply a rule to a range
- Select the cells you want to validate, for example
C2:C100. - Open Data > Data validation. A side panel titled "Data validation rules" opens.
- Choose Add rule.
- Check that the Apply to range box shows the range you expect. You can edit it by hand or use the grid icon to pick a new one.
- Choose the criteria, set the invalid-input behavior, and select Done.
Selecting a whole column such as C:C works, but it applies the rule to over a thousand empty rows and to the header cell. A header like "Status" will then fail a list rule that only allows "Not started", "In progress" and "Done". Starting the range at row 2 avoids this.
The Apply to range box accepts several ranges separated by commas, such as C2:C100, F2:F100. Both ranges then share one rule. Changing the rule later changes both, which is useful when two columns must always offer the same options.
The rules side panel
The side panel lists every rule on the current sheet. Each entry shows the range, the criteria, and a short summary. Selecting an entry opens it for editing.
Two details are easy to miss:
- The panel lists rules for the current sheet only. A rule on another sheet does not appear until you switch to that sheet.
- Rules are listed individually even when they look the same. If you see two entries with the same criteria on adjacent ranges, they are separate rules and must be edited separately.
Edit a rule
Open the rule from the side panel and change what you need. The change applies to the whole Apply to range, not only to the cell you had selected when you opened the panel.
Common edits:
- Add or remove an item in a typed list.
- Change the range a drop-down reads from.
- Switch between reject and warning behavior.
- Extend the Apply to range after you add rows to the table.
Editing a rule does not change values already in the cells. If you remove "Done" from a status list, cells that already contain "Done" keep that value. They are now invalid against the new rule. Sheets marks such cells with a small red triangle in the corner, but only when the rule's behavior is set to show a warning. With a reject rule, existing invalid values stay in place and are not flagged in the same way, so check the data yourself after editing a list.
Copy and paste rules
Validation travels with ordinary copy and paste. If you copy C2 and paste it into C3:C20, the values, formatting and the rule all come along. This is the quickest way to extend a rule, but it also overwrites the target's values.
To copy only the rule, use Paste special:
- Copy a cell that has the rule.
- Select the target range.
- Choose Edit > Paste special > Data validation only.
The target cells keep their values and formatting and receive the rule.
Pasted rules create a new rule for the target range. They do not link back to the source. Editing the original afterwards does not change the copies. If you need many places to share one list, point each rule at the same range (see the earlier chapter on range-driven drop-downs) instead of copying typed lists around.
What happens to references when you copy
Rules that use cell references behave like formulas when they are copied.
| Rule type | Reference in the rule | Result after copying down |
|---|---|---|
| Dropdown (from a range) | `Lists!$A$2:$A$10` | Still points to the same list |
| Dropdown (from a range) | `Lists!A2:A10` | The range shifts down by one row per row copied |
| Custom formula | `=COUNTIF($A$2:$A$100, A2)=1` | The range stays fixed, `A2` becomes `A3`, `A4` and so on |
| Custom formula | `=COUNTIF(A2:A100, A2)=1` | Both references shift, so the range shrinks or slides and the check becomes wrong |
The custom formula rule in the third row is the pattern from the duplicate-prevention example. The mixed references are deliberate. The $A$2:$A$100 part must stay fixed, and the A2 part must follow each row. If you copy a rule with the wrong mix, the rule still looks valid and still accepts input, but it checks the wrong cells. Always test a copied rule with a known bad value.
When a rule is applied to a range through the side panel, relative references are interpreted relative to the first cell of the range. That is why the formula for A2:A100 is written with A2.
Insert and delete rows
Inserting a row inside a validated range extends the rule to the new row. Inserting a row directly below the last row of the range does not. The new row has no rule.
Deleting rows shrinks the range. If you delete every row in a rule's range, the rule disappears.
For tables that grow, two approaches help:
- Apply the rule to a generously larger range, such as
C2:C1000. - Insert new rows in the middle of the table, or copy an existing row and insert it as a copy, so the rule is inherited.
Cutting and pasting cells moves the rule with them, and the original location loses the rule.
Find rules you forgot about
On a sheet you inherited, you may not know where rules are. Three ways to find them:
- Open Data > Data validation and read the side panel list.
- Look for cells with a drop-down arrow. Select one and the panel shows the rule that covers it.
- Look for red triangles in cell corners. They point to cells that fail a warning-style rule.
You can also find them with a script:
function listValidationRules() {
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getDataRange();
const rules = range.getDataValidations();
const found = [];
for (let r = 0; r < rules.length; r++) {
for (let c = 0; c < rules[r].length; c++) {
const rule = rules[r][c];
if (rule) {
const cell = range.getCell(r + 1, c + 1).getA1Notation();
found.push(cell + ': ' + rule.getCriteriaType());
}
}
}
Logger.log(found.join('\n'));
}Run it from Extensions > Apps Script. The log lists each validated cell and its criteria type, for example C2: VALUE_IN_LIST.
Remove rules
There are three ways to remove a rule, and they differ in scope.
- Remove one rule. In the side panel, open the rule and select the delete (trash) icon. The rule goes, and the values stay.
- Remove all rules on the sheet. In the side panel, choose Remove all at the bottom. This is fast but affects every rule on the sheet, so use it with care.
- Remove from part of a range. Select only the cells you want to clear, copy a cell with no validation, and use Paste special > Data validation only. Sheets then splits the original rule so that it covers the remaining cells.
The last method is the least obvious. Deleting a rule from the side panel removes it from its whole range. If you only want to unprotect a few cells inside a larger range, the paste approach is the one to use.
Clearing a cell's content with the Delete key does not remove its rule. Neither does Format > Clear formatting. Both leave the validation in place.
The script version of removal clears rules without touching values:
function clearStatusValidation() {
SpreadsheetApp.getActiveSheet().getRange('C2:C100').clearDataValidations();
}Because the script is limited to C2:C100, other validated ranges on the sheet are unaffected.
A workflow for safe changes
Changing a rule on a live sheet can break data that other people rely on. A short routine reduces the risk:
- Open the side panel and note the existing range and criteria.
- Make a copy of the sheet (right-click the tab, Duplicate) if the change is large.
- Edit the rule.
- Test with one valid value, one invalid value, and one pasted value. Pasting is covered in a later chapter, and it often behaves differently from typing.
- Check existing cells that now violate the rule, using a warning-style rule if you need the red triangles.
- Update old values with Find and replace.
The diagram below shows how a rule moves through its life on a sheet.
Common mistakes
- Rule on the header row. The header fails the list. Start the range below the header.
- Relative references in a copied rule. The rule silently checks the wrong range. Use
$on the parts that must stay fixed. - Expecting edits to fix old values. Rules check new input. They do not rewrite existing cells.
- Deleting the whole rule to unprotect a few cells. Use Paste special on only those cells instead.
- Assuming new rows are covered. A row added below the range has no rule.
Exercise
A rule applies to C2:C100 and lists "Not started", "In progress" and "Done". You want cells C50:C60 to accept any text, and you want to keep the rule on the rest. Describe the steps, and say what happens to the values in C50:C60.
Show answer
Copy any cell that has no validation (for example an empty cell outside the table). Select C50:C60, then choose Edit > Paste special > Data validation only. Sheets splits the original rule so it still covers C2:C49 and C61:C100, and C50:C60 has no rule. The values in C50:C60 do not change, because only the validation was pasted.
Exercise
You copy a custom rule =COUNTIF(A2:A100, A2)=1 from A2 down to A3:A100 using Paste special. Why will the duplicate check stop working correctly, and how do you fix the formula?
Show answer
The range A2:A100 is relative, so in each pasted row it shifts down by one row per row copied. Row 3 checks A3:A101, row 4 checks A4:A102, and so on, so earlier entries are no longer counted. Fix it by locking the range: =COUNTIF($A$2:$A$100, A2)=1. Only the second argument, A2, should stay relative.