HomeGoogle DocsSpreadsheetHow to Use Custom Formula in Data Validation in Google Sheets

How to Use Custom Formula in Data Validation in Google Sheets

It’s impossible to list every custom formula rule you can use in data validation because there is no limit. What matters is understanding how custom formulas work in data validation. Once you understand them, you can use many of your existing Google Sheets formulas to build custom validation rules.

How the Custom Formula Differs from Built-in Rules

Google Sheets provides several built-in data validation rules. Built-in validation rules work well for most situations. However, they validate only the value in the cell being edited. When your rule depends on another cell or requires more complex logic, use Custom formula is.

For example, you can’t allow data entry in one cell only when another cell contains a value. For such validation rules, Custom formula is is the only option.

Cell References in Custom Formula Data Validation

Similar to custom formulas in conditional formatting, relative and absolute references also play a key role in data validation.

The success of a custom formula often depends on using the correct cell reference. The following table summarizes how each reference type behaves.

ReferenceTypeChanges When AppliedCommon Use
A1RelativeRow and column changeValidate each cell based on its own value.
$A$1AbsoluteNeither row nor column changesUse one control cell for the entire validation range.
$A1MixedRow changes, column fixedValidate a cell using a value in the same row.
A$1MixedColumn changes, row fixedValidate cells based on column headers.

Understanding these reference types is essential for building effective custom validation rules.

Syntax

The syntax of the Custom formula is rule is:

=formula_returning_TRUE_or_FALSE

The formula is evaluated for every cell in the validation range.

Example:

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

This formula allows only unique values by rejecting duplicate entries.

A custom formula must return TRUE to accept the input and FALSE to reject it.

When to Use a Custom Formula

Use Custom formula is when the built-in data validation rules aren’t enough. Typical use cases include:

Custom Formula Examples in Data Validation

To understand relative and absolute references in data validation, let’s go through four examples.

Example 1: Relative Reference (A1)

In many cases, the built-in data validation rules are sufficient. However, when you need more complex validation, you must use a custom formula.

For example, the custom formula used in my Word Guess Game enforces multiple rules, such as:

  • Allow only one letter per cell.
  • Prevent players from skipping rows.
  • Require players to reveal at least one clue before unlocking the next row.

The following example shows why a relative reference is required.

Assume you have an attendance sheet, and you want to allow only the attendance codes P, A, H, SL, EL, PL, and CL in the range B2:E8.

Google Sheets data validation using a relative reference to allow only valid attendance codes
  1. Select B2:E8.
  2. Click Data > Data validation > Add rule.
  3. Under Criteria, select Custom formula is.
  4. Enter the formula:
=OR(B2="P", B2="A", B2="H", B2="SL", B2="EL", B2="PL", B2="CL")
  1. Expand Advanced options and select Reject the input.
  2. Click Done.

The cell reference B2 is a relative reference. As the validation rule is applied across the range, Google Sheets automatically adjusts it for each cell. For example, the formula checks C2 in cell C2, D5 in cell D5, and E8 in cell E8.

If you enter a value other than the specified attendance codes, the rule rejects the input and displays the following warning:

There was a problem
The data that you entered in cell B2 violates the data validation rules set on this cell.

Example 2: Absolute Reference ($A$1)

Assume the range A2:A5 contains the labels Name, Age, City, and Country. Allow data entry in B2:B5 only when cell B1 is set to Yes.

Google Sheets data validation using an absolute reference to allow data entry only when the master switch is set to Yes

You can apply the following custom formula to the range B2:B5.

=$B$1="Yes"

Every cell in B2:B5 checks the same cell (B1).

When B1 is not Yes, Google Sheets rejects any new entries in B2:B5.

Note: If you want to control only a single cell, select B2 instead of B2:B5 before creating the validation rule.

This technique is useful in templates. For example, you can prevent accidental data entry by using a checkbox or a Yes/No switch to temporarily enable or disable a range. Although Google Sheets also provides Protect sheets and ranges, this method makes it easy to open and close input ranges without changing protection settings.

Example 3: Mixed Reference ($A1)

Assume the range A2:A5 contains student names. Allow users to enter scores in B2:B5 only when the corresponding student name is not blank.

Apply the following custom formula to the range B2:B5:

=$A2<>""

The column reference (A) is fixed, while the row reference changes automatically. Google Sheets evaluates the formula like this:

  • B2 checks A2.
  • B3 checks A3.
  • B4 checks A4.
  • B5 checks A5.

If you also want to apply the same rule to other columns, simply change the validation range from B2:B5 to B2:E5 (or any wider range). Each cell will continue checking the name in column A of the same row.

Example 4: Mixed Reference (A$1)

Assume item names are in A2:A5, and weekday names are in B1:H1.

Allow data entry only in weekday columns and prevent entry in the Saturday and Sunday columns.

Select the range B2:H5 and apply this custom formula:

=NOT(OR(B$1="Sat",B$1="Sun"))

The row reference (1) is fixed, while the column reference changes automatically. As the rule is applied across the range, it checks the corresponding column header:

  • B2 checks B1.
  • C2 checks C1.
  • D2 checks D1.
  • and so on.

The formula first checks whether the column header is Sat or Sun. If so, OR returns TRUE. The NOT function reverses that result, allowing data entry only in weekday columns.

FAQ

Can I apply multiple custom formulas (data validation rules) to the same cell?

No. You can apply only one data validation rule to a cell or range.

For example, a drop-down list and a checkbox are both data validation rules. If a cell already has one of these rules, you can’t apply another built-in rule or a custom formula on top of it.

If you need multiple conditions, combine them into a single custom formula using functions such as AND, OR, or NOT.

How do I refer to a cell on another sheet in a data validation custom formula?

This is a common source of confusion because conditional formatting requires the INDIRECT function when referring to a cell on another sheet.

However, in a data validation custom formula, you can refer to a cell on another sheet directly by including the sheet name. For example:

=Sheet1!$B$1="Yes"

If the sheet name contains spaces, enclose it in single quotes:

='Employee List'!$B$1="Yes"

No INDIRECT function is required.

Can I use functions like VLOOKUP, XLOOKUP, FILTER, or QUERY in a custom formula?

Yes, as long as the formula ultimately returns TRUE or FALSE. If it returns another value, wrap it in a logical test.

Why does my custom formula reject all input?

Common reasons include:

  • incorrect relative or absolute references
  • formula returns text instead of TRUE/FALSE
  • validation applied to the wrong range
  • referenced cells are blank

Conclusion

Once you understand how relative, absolute, and mixed references behave, creating custom validation rules becomes much easier. You can combine this knowledge with functions such as AND, OR, NOT, COUNTIF, MATCH, and REGEXMATCH to build powerful validation rules for almost any scenario.

If you want to learn more about data validation rules, custom formulas, and other tips, check out The Complete Guide to Data Validation in Google Sheets.

Prashanth K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Most Discussed

More like this

How to Create a Drop-Down List in Google Sheets

A drop-down list (or drop-down menu) in Google Sheets lets users select one or...

Google Sheets 50/30/20 Budget Template (Free & Automated)

Managing your money in a spreadsheet shouldn't feel like solving a math problem. This automated...

Free Student Assignment Tracker Template in Google Sheets

Keeping track of assignments doesn't have to be stressful. That's why I created this...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.