To keep a column clean — only positive whole numbers, only values in a range, no text — use Data Validation. It rejects anything that breaks the rule as it’s typed, so bad data never lands in the first place.
How it works
The rule “whole number, 1–100” accepts or rejects each entry.
| A | B | |
|---|---|---|
| 1 | Entry | Result |
| 2 | 42 | OK |
| 3 | 3.5 | Rejected (not whole) |
| 4 | 150 | Rejected (out of range) |
The formula
This is set in the Data Validation dialog (no cell formula), or as a Custom formula:
How it works
The dialog does the work; you just pick the rule:
- Select the cells to protect, then open Data → Data Validation.
- Set Allow to Whole number (this alone blocks decimals and text), then choose an operator like between and enter the limits (1 and 100).
- As someone types, Excel checks the value against the rule and rejects anything that fails — a decimal, text, or a number outside the range.
- Add a friendly prompt (Input Message tab) and a clear rejection note (Error Alert tab).
Need custom logic? Use Allow: Custom with a formula — e.g. force uppercase with =EXACT(A1, UPPER(A1)), or require a value to be a multiple of 5 with =MOD(A1, 5)=0.
Try it: interactive demo
Rule: whole number between 1 and 100. Type a value.
Variations
Decimals in a range
Switch Allow to Decimal for, say, 0 to 1 percentages.
Text length limit
Allow: Text length → less than or equal to 10 for short codes.
Custom: multiple of 5
Allow: Custom with a formula:
Pitfalls & errors
Validation only checks typed input. Pasting can bypass it. Use Circle Invalid Data to catch values pasted around the rule.
“Whole number” still allows negatives unless you set the range. Use between 1 and… or greater than 0 to require positives.
Custom formula references the active cell. Write the formula for the top-left cell of your selection (e.g. A1); Excel applies it relatively to the rest.
Practice workbook
Frequently asked questions
How do I restrict a cell to whole numbers in Excel?
How do I limit input to a number range?
How do I enforce custom rules like multiples of 5?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class