Allow only sensible entries with validation rules
Stop bad data at the door10 minPremium
Builds on Create a drop-down list with Data Validation.
A travel coordinator in Lyon collects hotel bookings from twelve teams in one shared sheet. People type 0 nights, check-in dates from last year and employee numbers with a digit missing, and she only finds out when the hotel's invoice arrives.
How it works
Select the cells, choose Data > Data Validation and set the rule on the Settings tab. Allow decides what kind of entry goes in, and Data sets its limits:
| Row | A | B | C |
|---|---|---|---|
| 1 | Allow | Lets in | Limits, for example |
| 2 | Whole number | Numbers without decimals | between 1 and 30 |
| 3 | Decimal | Any number | greater than 0 |
| 4 | Date | Dates | between two dates |
| 5 | Text length | Entries of a set number of characters | equal to 8 |
A limit can point at a cell, such as =$F$1, so changing the limit means typing a new value in that cell, and the rule stays as it is.
The Input Message tab shows a note while one of the cells is selected, before anyone types: a title and a message that explain the rule. The Error Alert tab decides what happens to an entry the rule refuses:
- Stop, the default, offers Retry or Cancel, and the entry never goes in.
- Warning asks whether to continue, and Yes keeps the entry.
- Information says the entry isn't valid, and OK keeps it.
A rule checks entries typed after it exists. To find the ones that got in earlier, or through a Warning, click the arrow next to Data Validation and choose Circle Invalid Data. A red circle goes away when you fix its entry, and Clear Validation Circles removes them all.
Example
A rule for the number of nights: Whole number, between 1 and 30.
Common mistakes
- Decimal where a count is meant. It lets 2.5 nights in, so choose Whole number.
- Greater than where the limit itself is allowed. Greater than 0 refuses 0, so use greater than or equal to, or between.
- Limits in cells without $ signs, such as
=F1. Each cell below reads a cell one row lower, often an empty one. - Warning or Information for a value that must never go in. One click on Yes or OK keeps it, so use Stop.
In short
- Allow picks the kind of entry, and Data sets the limits, typed or taken from cells with $ signs.
- An input message explains the rule before anyone types.
- Stop refuses a wrong entry. Warning and Information let people keep it.
- Circle Invalid Data finds the entries that broke the rule before it existed.
Practice
Premium5 exercises: 4 data validation rules and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in