How to Prevent Duplicate Entries in Google Sheets: Data Validation Rules, Warnings and a Small Script (2026)
Removing duplicates after the fact works, but it is nicer when the repeat never gets in: a member ID typed twice, an asset tag entered by two people, an email added to a list it is already on. Google Sheets can refuse a value that already exists in a column, or accept it and mark it for review, with one data validation rule. This guide sets that rule up, shows the variations people actually need (ignore case and spaces, two-column keys, check another tab), and covers the gaps: form responses, pasting and scripts.
The example
A Members tab with a header row. Column A holds the member email, column B the name, column C the join date. Every email may appear only once.
| A: Email | B: Name | C: Joined | |
|---|---|---|---|
| 2 | ana@x.com | Ana | 2026-03-02 |
| 3 | bo@x.com | Bo | 2026-03-05 |
| 4 | cy@x.com | Cy | 2026-04-11 |
The goal: typing bo@x.com into A5 is refused (or flagged), while dee@x.com goes in normally.
Before you start: clean what is already there. The rule checks new entries; it does not delete existing repeats, it only marks them as invalid. Find and remove duplicates first, or highlight them to review by hand.
Method 1: reject duplicates with data validation
- Select the cells that must stay unique, starting below the header: click A2, then press Ctrl+Shift+↓, or type
A2:Alater in the range box to cover the whole column, including future rows. - Choose Data › Data validation, then Add rule. The Data validation rules panel opens on the right.
- Under Criteria, choose Custom formula is and enter:
=COUNTIF($A$2:$A, A2)=1
- Click Advanced options. Under If the data is invalid: choose Reject the input. Optionally tick Show help text for a selected cell and write something like “This email is already in the list.”
- Click Done, then test it by typing an email that is already in column A.
Why the formula looks like that. The rule is evaluated for every cell in the range as if the formula were written in that cell. $A$2:$A is locked, so every cell counts against the whole column. A2 is relative, so in A5 it becomes A5. If the value appears exactly once (itself), the formula is TRUE and the entry is accepted; a second copy makes it FALSE. Always write the relative reference as the first cell of the range you selected, or every cell will check the wrong value.
Method 2: warn instead of block
For names, emails in a sign-up list, or anything where a repeat is occasionally legitimate, choose Show a warning instead of Reject the input in step 4. The value is accepted, and the cell gets a small red marker in its corner; hovering shows the warning. That keeps data entry moving while making repeats easy to spot.
If you want only the later copies flagged, so the original entry stays clean, use a running count that looks only at the rows above:
=COUNTIF($A$2:A2, A2)=1
Here the end of the range is relative too, so in A5 it checks $A$2:A5. The first bo@x.com passes; a later one fails. With Reject the input this behaves like Method 1 for new rows at the bottom, but it will not stop someone from typing a copy above the original.
Variations
Ignore case, extra spaces and wildcards
COUNTIF already treats Ana@X.com and ana@x.com as equal, but it does not ignore a trailing space, and it treats *, ? and ~ in the value as wildcards, which matters for SKUs and codes. This version compares cleaned text exactly:
=SUMPRODUCT(--(TRIM(LOWER($A$2:$A))=TRIM(LOWER(A2))))=1
For harder near-matches (Gmail dots, phone formats, typos) a validation formula gets unwieldy; see duplicates that don’t match exactly.
Case-sensitive IDs
If ab12 and AB12 are genuinely different codes, use EXACT:
=SUMPRODUCT(--EXACT($A$2:$A, A2))=1
Unique combination of two columns
A person may sign up for several dates, but not twice for the same date. Select A2:B (both columns) and use:
=COUNTIFS($A$2:$A, $A2, $B$2:$B, $B2)=1
The $ before the column letters matters: the rule covers two columns, and without it the B-column cells would compare column B against column A.
Not already on another tab
To refuse an email that is already on an Archive tab as well as in this column, combine two checks. Validation formulas refer to other tabs through INDIRECT:
=AND(COUNTIF($A$2:$A, A2)=1, COUNTIF(INDIRECT("Archive!A2:A"), A2)=0)
INDIRECT takes the range as text, so it does not update if you rename the Archive tab; edit the rule if you do. For a full two-list comparison, see compare two columns or two sheets.
Where validation does not reach
- Google Form responses. Rows written by a form are not blocked by data validation. In the form, Settings › Responses › Limit to 1 response stops repeat submissions, but it requires respondents to sign in to Google. Otherwise, list repeats on a separate tab (adjust the tab name and the key column):
=FILTER('Form Responses 1'!A2:Z, 'Form Responses 1'!C2:C<>"", COUNTIF('Form Responses 1'!C2:C, 'Form Responses 1'!C2:C)>1)To keep only the newest response per person, see remove duplicates but keep the latest row. - Scripts, imports and other apps that write to the sheet are not blocked either; invalid values may simply get marked.
- Normal paste can replace the rule. Pasting cells from elsewhere copies their formatting and validation along with the values, which can overwrite your rule in the pasted cells. Paste with Ctrl+Shift+V (Paste special › Values only) to keep it, and reopen Data › Data validation now and then to check the rule’s range is still whole.
- Editors can delete the rule. Anyone who can edit the sheet can edit or remove the validation. For shared sheets, protecting the range (or keeping a highlight rule as a second line of defense) helps.
Method 3: a small onEdit script
If you want the duplicate undone with a clear message naming the row that already has the value, a simple onEdit script can do that. It ignores case and extra spaces, puts back what was in the cell before, and shows a toast. Change the tab name and column at the top.
// Extensions › Apps Script › paste › Save. No triggers to install: onEdit runs by itself.
// It checks your own typing and pasting only, not form submissions or other scripts.
const SHEET = 'Members'; // tab to protect
const KEY_COL = 1; // 1 = column A
const HEADER_ROWS = 1; // rows above the data
function onEdit(e) {
const r = e.range;
const sh = r.getSheet();
if (sh.getName() !== SHEET || r.getColumn() !== KEY_COL) return;
if (r.getNumRows() !== 1 || r.getNumColumns() !== 1 || r.getRow() <= HEADER_ROWS) return;
const typed = norm(e.value);
if (!typed) return; // cell cleared
const keys = sh.getRange(HEADER_ROWS + 1, KEY_COL, sh.getLastRow() - HEADER_ROWS, 1).getValues();
const i = keys.findIndex((k, n) => n + HEADER_ROWS + 1 !== r.getRow() && norm(k[0]) === typed);
if (i === -1) return;
if (e.oldValue === undefined) r.clearContent(); else r.setValue(e.oldValue);
e.source.toast(`"${e.value}" is already in row ${i + HEADER_ROWS + 1}, so the edit was undone.`, 'Duplicate', 8);
}
function norm(v) { // ignore case and extra spaces
return String(v === undefined || v === null ? '' : v).trim().replace(/\s+/g, ' ').toLowerCase();
}
Simple triggers like onEdit run only for edits a person makes in the sheet, so form submissions and other scripts are not checked, and multi-cell pastes are skipped by design. It reads the whole key column on every edit in that column, which is fine for a few thousand rows.
Pitfalls
- Wrong first cell in the formula. If you selected A2:A but wrote
A1in the formula, every cell checks the value one row above it. Match the relative reference to the top-left cell of the range. - Whole column including the header. Selecting all of column A puts the header under the rule too; start at row 2.
- Values that look equal but aren’t.
00123stored as text and123stored as a number, or an email with a trailing space, can slip past COUNTIF. Use the TRIM/LOWER version, and format ID columns as plain text (Format › Number › Plain text) before typing codes with leading zeros. - Very large ranges. SUMPRODUCT over an open-ended column is recalculated for each check; on tens of thousands of rows, prefer COUNTIF or limit the range, for example
$A$2:$A$5000.
FAQ
How do I stop duplicates from being entered in a column in Google Sheets?
Select the column range (for example A2:A), choose Data › Data validation › Add rule, set Criteria to Custom formula is, enter =COUNTIF($A$2:$A, A2)=1, then under Advanced options choose Reject the input and click Done. A value that already exists in the column is refused when someone types it.
Should I choose Show a warning or Reject the input?
Reject the input blocks the entry and shows an error, which suits IDs that must be unique. Show a warning accepts the value but marks the cell, which suits names or emails where a repeat is sometimes legitimate and you want to review it later.
Why does my duplicate rule not work on Google Form responses?
Data validation checks what people type or paste into the sheet. Rows written by Google Forms or by scripts are not blocked. Flag form duplicates with a formula on another tab instead, or use the form's own Limit to 1 response setting, which requires respondents to sign in.
How do I make the rule ignore upper and lower case and extra spaces?
COUNTIF already ignores case. To also ignore leading and trailing spaces and avoid wildcard matches, use =SUMPRODUCT(--(TRIM(LOWER($A$2:$A))=TRIM(LOWER(A2))))=1 as the custom formula.
How do I prevent duplicates across two columns, like name plus date?
Select both columns (for example A2:B) and use =COUNTIFS($A$2:$A, $A2, $B$2:$B, $B2)=1. The dollar signs before the column letters keep the formula pointing at columns A and B in every cell of the range.
Does data validation remove duplicates that are already there?
No. Existing duplicates stay; cells that break the rule are only marked as invalid. Clean the column first with Data › Data cleanup › Remove duplicates or one of the formula methods, then add the rule.
Install free from Google Workspace MarketplaceSee SheetDupes
Want to test it first? Try it on sample data (makes a copy of a 12-row example sheet in your Drive).
Related guides
- How to Find and Remove Duplicates in Google Sheets: Highlight, Count, Delete and Keep the Original (2026)
- How to Highlight Duplicates in Google Sheets: Conditional Formatting Formulas for One Column, Whole Rows, Repeats Only and Two Sheets (2026)
- How to Compare Two Columns or Two Sheets in Google Sheets to Find Matches and Duplicates (2026)
- Duplicates That Don’t Match Exactly in Google Sheets: Case, Extra Spaces, Gmail Dots, Phone Formats and Typos (2026)
- How to Remove Duplicates in Google Sheets but Keep the Latest, First or Highest Row per Key (2026)
- How to Count Duplicates in Google Sheets: per Value, Extra Rows, Unique Counts and Why the Numbers Disagree (2026)
- How to Combine Two Lists or Several Tabs in Google Sheets Without Duplicates: VSTACK, UNIQUE, One Row per Key and Other Files (2026)
- How to Merge Duplicate Rows in Google Sheets: Sum the Numbers, Join the Notes and Fill the Blanks (2026)
- UNIQUE vs Remove Duplicates in Google Sheets: Live or Static, Letter Case, Spaces, Columns and Headers (2026)
- How to Remove Duplicates Within a Cell in Google Sheets: Comma-Separated Lists, Tags, Line Breaks and Letter Case (2026)
- How to Show Only the Duplicates in Google Sheets: Filter Duplicate Rows, List Repeated Values and Find Rows That Appear Once (2026)
- How to Find Duplicates Across Multiple Columns in Google Sheets: Rows That Match on Two or More Columns, and Values Repeated Anywhere in a Range (2026)
- How to Remove Duplicates Automatically in Google Sheets: Apps Script on a Daily Timer, on Form Submit or From a Menu (2026)
- How to Find Duplicates in Google Sheets but Ignore Blank Cells: Highlight, Count, List and Remove Without Empty Rows Getting in the Way (2026)
- How to Find Duplicate Transactions in Google Sheets: Double-Imported Rows, Invoices Paid Twice and Same-Amount Charges Within a Few Days (2026)
- How to Format Phone Numbers in Google Sheets: Strip Dashes and Spaces, Show (555) 010-1234, Handle +1 and Extensions, Then Find Duplicate Contacts (2026)
- How to Change Text Case in Google Sheets: UPPERCASE, lowercase, Proper Case Names, Sentence Case and Duplicates That Differ Only in Case (2026)
Data validation steps follow Google’s Docs Editors Help page on data validation and dropdowns; function behavior is from the help pages for COUNTIF, COUNTIFS and INDIRECT, and simple triggers from Google’s Apps Script triggers guide. Instructions refer to Google Sheets as it worked on November 18, 2026; menu names can change. Google Sheets is a trademark of Google LLC and this site is not affiliated with Google. Questions or corrections: hello@loomwise.app.