Sub topic 16
Limiting Entries with Data Validation
This chapter assumes you can select cells, type and commit entries with Enter, and know that Excel stores numbers, text, and dates differently. Data validation uses those ideas to stop bad entries before they land in a cell.
What data validation does
Data validation is a rule attached to a cell or range. When someone types in a validated cell, Excel checks the entry against the rule. If the entry fails, Excel can reject it or warn about it.
Validation only checks what is typed. It does not check values that are pasted over the cell, and it does not check existing values until you ask. Pasting replaces the rule along with the contents.
Setting a rule
- Select the cells to protect, for example B2:B20.
- Open the Data tab and choose Data Validation.
- On the Settings tab, pick a type under Allow.
- Set the condition and its limits, then choose OK.
Common types:
| Allow | What it accepts | Example |
|---|---|---|
| Whole number | Integers within a condition | Between 1 and 100 |
| Decimal | Any number within a condition | Greater than 0 |
| List | A value from a fixed set | Yes, No, Maybe |
| Date | Dates within a range | After 2026-01-01 |
| Text length | Text of a limited length | Equal to 5 |
| Custom | A formula that returns TRUE or FALSE | Your own rule |
For the List type, type the items in the Source box separated by commas, or point to a range of cells. Excel then shows a drop-down arrow in the cell.
The three message tabs
Each rule has three tabs that control what the user sees.
- Input Message appears when the cell is selected. Use it to say what is expected.
- Error Alert appears when an entry fails. Its Style sets the strength of the response.
- Settings holds the rule itself.
The Error Alert style matters:
| Style | Behavior |
|---|---|
| Stop | Rejects the entry. The user must retry or cancel. |
| Warning | Explains the problem and lets the user accept the entry anyway. |
| Information | Notes the problem and lets the entry through. |
Use Stop when a wrong value breaks later work. Use Warning when exceptions are legitimate.
A custom rule
The Custom type uses a formula written for the first cell of the selected range. This rule, applied to A2:A20, rejects a code that is not exactly five characters:
=LEN(A2)=5Excel adjusts the reference for each cell in the range, as it does when you copy a formula. Because the formula refers to A2 without dollar signs, A3 is checked with A3, and so on.
The next rule accepts only text entries and rejects numbers:
=ISTEXT(A2)Finding bad values that already exist
Validation does not look back at old data. To find existing entries that break the rule, open the Data Validation drop-down and choose Circle Invalid Data. Excel draws red circles around the offending cells. Choose Clear Validation Circles to remove them.
Removing a rule
Select the cells, open Data Validation, and choose Clear All. This removes the rule and its messages but leaves the cell contents alone. Clearing contents with Delete does not remove the rule.
Common errors
- Setting the rule on one cell and expecting it to cover the column. Select the whole range first.
- Leaving "Ignore blank" ticked in a way you did not intend. Blank cells then pass the check.
- Using a List source with a space after each comma and being surprised by the items. Check the drop-down text.
- Assuming validation fixes old data. Use Circle Invalid Data.
Exercise
You applied a Stop rule to B2:B20 that allows whole numbers from 1 to 100. A coworker copies a cell containing 500 from another sheet and pastes it into B5. What happens, and how can you find the problem afterward?
Show answer
The paste succeeds, because validation checks only typed entries and the paste also replaces the rule in B5. To find the bad value, use Data Validation, Circle Invalid Data, which circles 500 in any cell that still has a rule. B5 no longer has one, so you must reapply the rule to B2:B20 first and then circle invalid data.
Exercise
Write a Custom rule formula for A2:A20 that accepts only entries longer than three characters.
Show answer
=LEN(A2)>3