Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

Data Validation in Google Sheets with a Custom Formula: Practical Examples

Data validation in Google Sheets with a custom formula
Illustration: Data validation in Google Sheets with a custom formula

To use data validation in Google Sheets with a custom formula, select the cells, open Data, then Data validation, add a rule, and choose "Custom formula is". The formula must return TRUE for allowed entries. For example =COUNTIF($A$2:$A$100, A2)=1 blocks duplicate entries in column A. This guide shows the steps, formulas for dates, text length, email format and numbers, and how to choose between rejecting input and showing a warning. The menu names can change slightly, so look for the matching option if yours differs. The sample data is made up.

Add a custom formula rule

  1. Select the range, for example A2:A100.
  2. Click Data, then Data validation.
  3. Click Add rule.
  4. In Criteria, choose Custom formula is.
  5. Type the formula, written for the first cell of the range.
  6. Choose what happens with bad input, then click Done.

Write the formula for the top-left cell. Sheets adjusts the references for the other cells, the same way it does for conditional formatting. Use dollar signs to lock anything that must stay fixed.

Add a custom formula data validation rule in Google Sheets
Six steps (illustration).

Reject the input or show a warning

Under "If the data is invalid" you can pick "Show a warning", which lets the user continue, or "Reject the input", which blocks the entry. Use a warning for guidance and reject for rules that must never break. You can also add help text that appears when the cell is selected.

Reject the input or show a warning in Google Sheets data validation
Pick the strictness (illustration).

Block duplicate entries

=COUNTIF($A$2:$A$100, A2)=1

The count of the typed value in the column must be exactly 1, so a second copy is invalid. If you want to clean up duplicates that already exist, see how to remove duplicates in Google Sheets.

Block duplicate entries with data validation in Google Sheets
COUNTIF equals 1 (illustration).

Only allow dates in the future

=AND(ISNUMBER(B2), B2>=TODAY())

ISNUMBER makes sure the entry is a real date, and the second test checks that it is today or later. Google Sheets also has a built in Date criteria, which is simpler when you only need a date range.

Limit text length

=LEN(C2)<=50

This allows up to 50 characters, which is handy for short descriptions.

Check an email address

=REGEXMATCH(D2, "^[^@ ]+@[^@ ]+[.][^@ ]+$")

This is a simple pattern for something shaped like an email. It does not prove that the address exists. The built in "Text is valid email" criteria is easier and does a similar job. Regular expressions are explained in our REGEXEXTRACT guide.

Allow only numbers in a range

=AND(ISNUMBER(E2), E2>=0, E2<=100)

For a plain range, the built in "Number between" criteria does the same thing without a formula.

Require another cell to be filled first

=$A2<>""

Applied to column B, this only allows an entry in B when A in the same row is not empty. Note the dollar sign before A, which locks the column.

Custom formula examples for Google Sheets data validation
Date, length and number rules (illustration).

Combine with a drop-down

Custom formulas and lists solve different problems. For a choice list, see our drop-down list guide.

Limits to know

  • Validation only checks typing. Pasting values can bypass the rule in some cases, so test it.
  • It does not fix old data. Existing bad cells stay until edited.
  • Rules can be removed by anyone with edit access, so protect the range if it matters.

Questions and answers

Why does my custom formula always say invalid?

Check that the formula refers to the first cell of the range and returns TRUE or FALSE. A reference to the wrong row is the usual cause.

Can I use another sheet in the formula?

Custom formulas in data validation may not accept direct references to other sheets. Test it, and try a named range or INDIRECT if it fails.

How do I remove a rule?

Select the cells, open Data validation, and click Remove rule.

Does this work in Excel?

Excel has a similar Data Validation tool, with a Custom option under Allow.

العربية