How to Prevent Duplicate Entry in Google Sheets Per Row

formulasgoogle sheets

So using the example data below, how can I prevent a duplicate entry with an informative message. The duplicate entry should be based on the row and not the whole sheet.

enter image description here

So, if I was to add a second column named Colour2, and I added 'Blue' for Bob. I want it to prevent the entry with a suitable message. But I dont want it to prevent the entry of 'Blue' for Alex as he hasnt chosen Blue yet.

Best Answer

I have a feeling that the real-life implementation you have in mind will be more complex than the sample. But for your sample as given:

Add header "Colour2" into Column C.

Select cell C2.

Choose "Data" from the top menu, then choose "Data validation" from the drop-down menu.

When the Data Validation dialog opens, append ":C" to the end of the range showing in the top text box beside "Cell range:"

Click the drop-down next to "Criteria:" and choose "Custom formula is" from the bottom of that list.

In the textbox beside "Custom formula is," enter this formula: =COUNTIF(B2:C2,B2)<2

Beside "On invalid data:" check "Reject input."

Check the box beside "Appearance:", delete the technical language in that text box, and enter something that will serve as both a short preemptive tip and an explanation if a duplicate is entered (e.g., "Avoid duplicate entries").

Click the blue "Save" button.


Another "gentler" approach might be to use conditional formatting. It won't prevent duplicate input, but it will certainly let you know that you need to change duplicates to something else:

Add header "Colour2" into Column C.

Select cell C2.

Choose "Format" from the top menu, then choose "Conditional formatting" from the drop-down menu.

When the Conditional Formatting dialog opens, append ":C" to the end of the range showing in the text box below "Apply to range."

Click the drop-down below "Format cells if" and choose "Custom formula is" from the bottom of that list.

In the textbox below "Custom formula is," enter this formula: =COUNTIF(B2:C2,B2)>1

Click the mint green button that says "Default" under "Formatting style." Select the "123" in red font on a white background. Click the strikethrough button below that (the icon is a small "S" with a line through it).

Click the blue "Done" button, then close the Conditional Formatting dialog by clicking the "X" in the top right corner.

Now, any time a duplicate is entered, the text will turn red with a line through it — clear indication that it should be changed.