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: EmailB: NameC: Joined
2ana@x.comAna2026-03-02
3bo@x.comBo2026-03-05
4cy@x.comCy2026-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

  1. Select the cells that must stay unique, starting below the header: click A2, then press Ctrl+Shift+↓, or type A2:A later in the range box to cover the whole column, including future rows.
  2. Choose Data › Data validation, then Add rule. The Data validation rules panel opens on the right.
  3. Under Criteria, choose Custom formula is and enter:
    =COUNTIF($A$2:$A, A2)=1
  4. 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.”
  5. 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

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

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.

Already have duplicates to clear out? SheetDupes (disclosure: we make it) is a Google Sheets add-on that finds, highlights and removes duplicates from a sidebar. Pick the columns that define a duplicate, preview the matching groups, highlight the extra rows without changing any values, and only then remove or merge them. It copies a backup tab before it removes or merges anything, ignores extra spaces and, optionally, letter case and punctuation. Preview and Highlight are free on any size sheet; there is a 14-day free trial with no credit card, and writes remain free after the trial on sheets with up to 2,000 data rows during launch (through Jan 31, 2027; 500 after that). It only reads and writes the spreadsheet you have open, and your data is not sent to Loomwise. It is live on the Google Workspace Marketplace.
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

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.