How to Prevent Duplicates in Google Sheets

Published on

Data validation is a powerful feature in Google Sheets that helps maintain data quality by preventing incorrect or duplicate entries. This tutorial demonstrates how to use Data validation to stop duplicates in Google Sheets using custom formulas.

Why Use Data Validation to Prevent Duplicates?

Data validation ensures data accuracy by enforcing specific rules during data entry. While Google Sheets has many built-in rules, it lacks a default option to prevent duplicate entries. By using a custom formula, you can efficiently block duplicates across a range, ensuring clean and reliable data.

Features of the Custom Formula Rule

Here are the key features of my data validation rules that help prevent duplicates in your sheet.

  1. Versatility: The formula can prevent duplicates in:
    • Single or multiple columns
    • A selected range
    • An entire tab
  2. Supports Unique Combinations:
    It can also prevent duplicate combinations of two columns, making it useful for datasets with dependent values like product IDs and items.
  3. Set-and-Forget:
    Once applied, the rule automatically prevents duplicates without requiring further adjustments.
  4. Customizable Limit:
    Depending on your requirements, you can allow duplicates up to a specified number of times.
  5. Flexible Response:
    Choose to either reject duplicates outright or flag them for review.

How to Prevent Duplicates in Google Sheets

Step-by-Step Guide to Applying Data Validation

Follow these steps to prevent duplicates in the range A1:G using a custom formula:

How to Prevent Duplicates in Google Sheets Using Data Validation

Formula:

=LET(rule, COUNTIF($A$1:G, INDIRECT(ADDRESS(ROW(), COLUMN(),))), ISBETWEEN(rule, 1, 1))

Steps:

  1. In your Google Sheet, select the range where you want to apply the rule (e.g., A1:G).
  2. Go to Data > Data validation in the menu.
  3. Click the + Add rule button in the sidebar.
  4. Under Criteria, select Custom formula is and paste the formula.
  5. Under Advanced options, decide whether to:
    • Show a warning: Flag duplicates for review.
    • Reject the input: Block duplicates from being entered.
  6. Click Done to apply the rule.
Prevent Duplicates in Google Sheets: Data Validation Settings

In the above steps, we used the formula for the range A1:G. If your range is different, replace $A$1:G in the formula with the desired range, such as $C$1:C100.

How to Allow Duplicates a Limited Number of Times

If you need to allow duplicates up to n times, modify the formula accordingly.

Example: Allow Duplicates Twice

Formula:

=LET(rule, COUNTIF($A$1:G, INDIRECT(ADDRESS(ROW(),COLUMN(),))), ISBETWEEN(rule, 1, 2))

As you can see, the change is minimal. I have simply replaced the third argument in the ISBETWEEN function from 1 to 2. This demonstrates that the third argument controls the value of n (the maximum number of allowed duplicates).

This formula permits duplicates to appear up to two times.

For a specific column (e.g., column A), update the range $A$1:G to $A$1:A.

Steps:

  1. Follow the same data validation steps as above.
  2. Use this modified formula instead.

Preventing Duplicate Combinations of Two Columns

Previously, we discussed rejecting duplicate values outright. In that context, a duplicate was defined as a single value appearing more than once, prompting it to be flagged or rejected.

But what if you want to prevent duplicate combinations across two columns?

For instance, imagine you have data in columns A and B with headers in row 1 (e.g., A1:B1). Column A contains Product IDs, and column B contains Items. If the same Product ID and Item combination appear more than once, you might want to flag it or reject the input.

Here’s the rule to prevent duplicate combinations for the range A2:B, leaving the header row untouched:

=LET(rule, ArrayFormula(COUNTIFS($A$2:$A&"|"&$B$2:$B, $A2&"|"&$B2)), ISBETWEEN(rule, 1, 1))
Prevent Duplicate Combinations of Two Columns in Google Sheets

Steps:

  1. Select the range where the rule should apply (e.g., A2:B excluding the header row).
  2. Open Data validation and add a new rule.
  3. Paste the above formula into the Custom formula is field.
  4. Choose whether to flag or reject duplicate combinations.
  5. Click Done.

This ensures unique combinations of values across two columns.

Important Note: Copy-Pasting and Data Validation

Data validation works only during manual data entry or formula-driven changes. Copy-pasting bypasses validation, meaning duplicate entries can still be added this way.

Tips to Address This:

  • Add a bold, highlighted note at the top of your sheet warning users about the limitations of copy-pasting.
  • Regularly review your data for duplicates using the Remove Duplicates tool in Google Sheets.

Additional Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Perform Case-Sensitive XLOOKUP in Excel with EXACT

We may not always need to perform a case-sensitive XLOOKUP for product names in...

Filter the Last 7 Days in Excel Using the FILTER Function

You may have records spanning several days and want to filter the last 7...

Find Missing Dates in Excel

You can find missing dates in a list in Excel using either a VLOOKUP...

Generate Unique Random Numbers in Excel with Dynamic Arrays

Unique random numbers refer to random numbers without duplicates. Generating such numbers is straightforward...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

16 COMMENTS

  1. Hi!

    Just found this trying to prevent duplicates in a sheet, But I have unique data based on 2 cells in a row , “SET” and “ID”
    Is there any way to prevents duplicate Combinations of the 2? As both will have duplicates individually (IE Set will have the Value GP1 Several times, And ID will have the value 3 several times) But The same combined Value should not be allowed (IE the Combination of GP1 3 can’t be duplicate)

    • I’ve updated the post to include a section that addresses your problem. I’ve also modified the earlier formulas for greater flexibility. I hope you check it out and leave your feedback below.

  2. Hi, Prashanth,

    I have an HTML form submitted to Google Sheets when it’s filled out.

    But every time a new entry is created, it duplicates the entry in Google Sheets and sends two email notifications.

    It should be one entry to Sheets and one email notification. Have you ever seen anything like this or possibly have a fix?

  3. Hi, I want

    My Sheet1 C2:C get data validations and don’t make duplicates from another sheet range J1:J

    Is that possible using data validation?

  4. Hi there. Is it possible to check for several ranges at the same time? Different sheets with similar information? If so, how do I do that? I can’t seem to “ctrl – Select” them all, nor comma it’s ranges.

  5. Is it possible to check for a maximum number of occurrences as your formula allows AND the entered number to be less than a stated number?

    For example, I want to allow a maximum number of duplicates to be 4 and the entered number to be between 1 and 20 (> 0 but < 21).

    • Hi, Leo,

      That’s correct! The “reject input” may not have any effect. But the duplicates will get flagged anyhow.

      The problem with data validation and conditional formatting are it get copied along with the values.

  6. Thanks, it has worked. Now, will the formula apply to all data entered in column A? Again, how can I disable the main menu to allow the users just to enter data only without interfering with my settings?

    • Hi, Herbert,

      It depends on the range that you have selected. I am talking about the “Cell range” in the data validation settings. You can refer my screenshot above where I have selected the range A1:G. For entire column A you can change that to A1:A.

      I don’t know anything about disabling menu in Google Sheets. I suggest you to use the Protect Sheet feature that you can find under the Tools menu in Google Sheets. Only give access to the required cell range for editing. This probably prevents them from interfering with your settings.

      Check this Google Sheets Documentation for more details.

      https://support.google.com/docs/answer/1218656?co=GENIE.Platform%3DDesktop&hl=en

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.