Exceljet

Quick, clean, and to the point

List contains duplicates

Excel formula: List contains duplicates
Generic formula 
=SUMPRODUCT(COUNTIF(data,data)-1)>0
Explanation 

Does a range contain duplicate values? If you want to test a range (or list) for duplicates, you can do so with a formula that uses COUNTIF together with SUMPRODUCT.

In the example, there is a list of names in the range B3:B11. If you want to test this list to see if there are duplicate names, you can use:

=SUMPRODUCT(COUNTIF(B3:B11,B3:B11)-1)>0

How this formula works

Working from the inside out, COUNTIF first gets a count of every value in B3:B11 in the range B3:B11. Because we supplying a range (array) of cells for the criteria, COUNTIF returns an array of counts as a result. In the example shown this array looks like this:

{1;2;1;1;1;1;1;2;1}

Next 1 is subtracted, which yields an array like this:

{0;1;0;0;0;0;0;1;0}

Note that every 1 in the array (i.e. items that appear just once) has been converted to a zero.

Next, SUMPRODUCT adds of the elements in this array and returns the result, which in this case is the number 2, which is then tested for a >0 value.

Any time a list contains duplicates, there will be at least two 1's in the array summed by SUMPRODUCT, so a final result of TRUE means the list contains duplicates.

Handling blank cells

Empty cells in the range will cause the formula above to generate incorrect results. To filter out blank or empty cells, you can use the following alternative:

=SUMPRODUCT((COUNTIF(list,list)-1)*(list<>""))>0

Here we use the logical expression list<>"" to force all values associated with blank cells to zero.

Author 
Dave Bruns

Excel Formula Training

Formulas are the key to getting work done in Excel. In this step-by-step training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Start building valuable skills with Excel formulas today. Learn more.

I have used vlookup a lot and read some about index and match, but decided to add extra columns and stay with vlookup, however, your site was so very clear that making the switch (only where necessary) was very easy. For the first time, I understand index and match match. Thank you. -Garth
Excel foundational video course
Excel Pivot Table video training course
Excel formulas and functions video training course
Excel Shortcuts Video Course
Excel Charts video training course