Data Validation Rules in Excel: Limit What Users Can Enter
By ExcelReady TeamUpdated 6 min read
The short answer
Select the cells, go to Data > Data Validation, and choose what to allow: a whole number, decimal, list, date, time, text length or a custom formula. Set the limits, add an input message and an error alert, and click OK. Excel then rejects typed entries that break the rule. Custom rules use any formula that returns TRUE for valid entries.
Key takeaways
- Data validation is on the Data tab: pick a type, set the limits, then add an input message and an error alert.
- A custom rule is a formula that must return TRUE for the entry to be accepted, such as =AND(ISNUMBER(B2),B2>=1,B2<=50).
- Write the custom formula for the top-left cell of your selection; Excel adjusts it for the other cells.
- Validation only checks what people type. Pasted values and data that was already there are not checked.
- Use Circle Invalid Data to find entries that break the rule after the fact.
On this page+
Data validation rules in Excel limit what people can type into a cell: only whole numbers from 1 to 50, only dates this year, only items from a list, or only codes that are exactly six characters long. You set them once, and Excel rejects wrong entries with a message. This guide covers the built-in rule types, custom formula rules with AND, ISNUMBER and LEN, and the limits you should know before you rely on them.
How to add a data validation rule#
A data validation rule is set from the Data tab in four steps:
- Select the cells to control, for example B2:B200.
- Go to Data > Data Tools > Data Validation. On Windows, the keyboard path is Alt, A, V, V.
- On the Settings tab, choose what to allow in the Allow box, then set the limits.
- Click OK.
Now type 75 into a cell that only allows 1 to 50, and Excel shows an error and refuses the entry. The rule stays with the cell when you sort or fill it down.
The Ignore blank box is ticked by default. It means an empty cell is always allowed. Untick it only if blanks should count as errors, and remember that it doesn't force anyone to fill the cell in.
The built-in rule types#
The Allow box offers eight options. Each one has its own limits, such as between, greater than or equal to.
| Allow | What it accepts | Example rule |
|---|---|---|
| Any value | Everything (no rule) | Used to switch a rule off |
| Whole number | Integers only | Between 1 and 50 |
| Decimal | Any number | Greater than or equal to 0 |
| List | Only items from a list | Pending, Shipped, Delivered |
| Date | Dates only | Between 1/1/2026 and 31/12/2026 |
| Time | Times only | Between 9:00 and 17:00 |
| Text length | Text with a set number of characters | Equal to 6 |
| Custom | Anything your formula returns TRUE for | =AND(ISNUMBER(B2),B2>=1,B2<=50) |
The List type creates a drop-down list. The guide to creating a drop-down list in Excel covers it step by step, and how to make a drop-down list that grows with your data shows how to keep it up to date. Limits can also point at cells. For example, a Date rule with a start date of =TODAY() blocks past dates.
How to write a custom validation rule#
A custom rule is a formula that returns TRUE when the entry is allowed and FALSE when it isn't. TRUE and FALSE are logical values, and comparisons like B2>=1 produce them. If you're new to this, practise TRUE and FALSE comparisons first.
Write the formula for the top-left cell of your selection. If you selected B2:B200, write it for B2. Excel moves the reference down for each cell, just as it does when you fill a formula down. Use $ signs for anything that must stay fixed, like a list range.
Here are custom rules that come up often:
| Rule | Custom formula (for cell A2 or B2) |
|---|---|
| Exactly 6 characters | =LEN(A2)=6 |
| Starts with "EM" and is 6 characters | =AND(LEFT(A2,2)="EM",LEN(A2)=6) |
| A number from 1 to 50 | =AND(ISNUMBER(B2),B2>=1,B2<=50) |
| No duplicates in A2:A200 | =COUNTIF($A$2:$A$200,A2)=1 |
| No spaces at the start or end | =A2=TRIM(A2) |
| Text only, no numbers | =ISTEXT(A2) |
AND returns TRUE only when every test inside it is TRUE. OR returns TRUE when at least one test is TRUE. The AND function guide explains both, and you can practise AND, OR and NOT in a live spreadsheet. LEN counts characters, including spaces; see the LEN function guide.
Why use ISNUMBER in a custom rule?#
ISNUMBER makes sure the entry is a real number, not text. Without it, a rule such as =B2>=1 can accept text: in Excel, any text is treated as greater than any number in a comparison, so "ten" passes B2>=1. Adding ISNUMBER closes that gap:
=AND(ISNUMBER(B2),B2>=1,B2<=50)The ISNUMBER function guide and the article on ISBLANK, ISNUMBER and ISTEXT cover the other IS functions. To use them confidently, practise the IS functions.
Test the rule in a cell first#
A custom rule gives no feedback while you write it, so test it in a normal cell first. Type the same formula next to your data and fill it down. Every row shows TRUE or FALSE, and you can see which entries would pass.
| A | B | D | |
|---|---|---|---|
| 1 | Order ID | Qty | Valid? |
| 2 | EM1042 | 12 | TRUE |
| 3 | EM10431 | 30 | FALSE |
| 4 | EM1044 | 75 | FALSE |
| 5 | EM1045 | ten | FALSE |
The test formula in D2 is =AND(LEN(A2)=6,ISNUMBER(B2),B2>=1,B2<=50). Row 3 fails because the ID has 7 characters. Row 4 fails because 75 is over 50. Row 5 fails because "ten" is text. Once the results look right, copy the formula into the Custom box and delete the test column.
To count how many rows break the rule in one cell, use SUMPRODUCT: =SUMPRODUCT((LEN(A2:A5)<>6)*1) counts IDs that are not 6 characters long (here, 1).
Input messages and error alerts#
An input message tells people the rule before they type, and an error alert tells them what went wrong. Both are tabs in the Data Validation box.
- Input Message: a short note that appears when the cell is selected, such as "Enter a quantity from 1 to 50."
- Error Alert: the message shown when the rule is broken. Choose one of three styles.
| Style | What happens |
|---|---|
| Stop | The entry is refused. The user must retry or cancel. |
| Warning | The user is asked "Continue?" and can accept the wrong value. |
| Information | The user is told, but the value is accepted. |
Use Stop for rules that must hold, like IDs that feed a lookup. Use Warning for soft limits, like an unusually large order. Write the message in plain words: say what is allowed, not just "Invalid entry".
What data validation can't do#
Data validation is a guide for people typing, not a lock. Know its limits:
- Pasting replaces the rule. If someone copies a cell and pastes it over a validated cell, the pasted cell's rules (or none) replace yours. Excel doesn't check the pasted value.
- Old data isn't checked. Adding a rule doesn't flag values already in the cells. Use Data > Data Validation (arrow) > Circle Invalid Data to circle them in red.
- Formulas aren't checked. Validation only applies to values typed into the cell, not to results calculated by a formula.
- Lists can point to other sheets. You can use a range on another sheet as the source, as the guide to a drop-down list from another sheet shows.
For real control, combine validation with sheet protection. The guide to protecting a sheet and locking cells shows how to leave only the input cells editable.
Practise it#
Every custom rule is a TRUE or FALSE formula, so the formula skill is what you need to practise. Practise AND, OR and NOT in a live spreadsheet, then practise the IS functions: you type each test and ExcelReady checks it instantly. Start with the row-3 test in the exercise on this page.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
The rule is: the Order ID must be exactly 6 characters and the quantity must be a number from 1 to 50. Click D3 and test row 3 with AND, LEN and ISNUMBER (it should return TRUE or FALSE).
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Notes | ||||
| 2 | Row 3 valid? | ||||
| 3 | |||||
| 4 | |||||
| 5 | ten | ||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 |
Tip: AND returns TRUE only when every test is TRUE. Test LEN(A3)=6, ISNUMBER(B3), B3>=1 and B3<=50.
Practise this in a lesson
Frequently asked questions
How do I set data validation rules in Excel?
Select the cells, go to Data > Data Validation, and on the Settings tab choose what to allow, such as Whole number between 1 and 50. Add an input message and an error alert on the other tabs, then click OK.
How do I use a custom formula in data validation?
Choose Custom in the Allow box and type a formula that returns TRUE for valid entries, written for the first selected cell. For example, =LEN(A2)=6 allows only entries that are exactly six characters long.
Why does data validation not stop pasted values?
Pasting a cell replaces its validation rule along with its value, so Excel doesn't check it. Protect the sheet or check the data afterwards with Circle Invalid Data.
How do I prevent duplicate entries with data validation?
Use a custom rule with COUNTIF, such as =COUNTIF($A$2:$A$200,A2)=1 for cells A2:A200. Excel then rejects a value that already appears in the range.
How do I remove data validation from cells?
Select the cells, open Data > Data Validation and click Clear All, then OK. This removes the rule but keeps the values already in the cells.