How to highlight duplicate values
Table of Contents
1. How to highlight duplicate values
The picture above shows duplicate values in column B, only the second or more duplicates are colored and easily identified.
To sort all duplicates to the bottom of the list for removal, creating a unique distinct list. See this blog post
How to create a unique list using conditional formatting in excel 2007
To color duplicate cells I use conditional formatting in excel. The conditional formatting formula in B3:B11:
1.1 Explaining CF formula
Step 1 - Expanding cell reference
The first argument in the COUNTIF function expands as the CF moves to cells below, this makes it easy to spot duplicate values as their count is 2 or larger.
Cell | First argument |
B3 | $B3:$B$3 |
B4 | $B4:$B$3 |
B5 | $B5:$B$3 |
Step 2 - Absolute cell reference
The second argument changes to the current cell.
Cell | Second argument |
B3 | B3 |
B4 | B4 |
B5 | B5 |
Step 3 - Count current value in expanding cell range
COUNTIF($B3:$B$3, B3)
becomes
COUNTIF("VV", "VV")
and returns 1
Cell | COUNTIF | Evaluates to | Result |
B3 | COUNTIF($B3:$B$3, B3) | COUNTIF("VV", "VV") | 1 |
B4 | COUNTIF($B4:$B$3, B4) | COUNTIF({"VV","AA"}, "AA") | 1 |
B5 | COUNTIF($B5:$B$3, B5) | COUNTIF({"VV","AA","DD"}, "DD") | 1 |
Step 4 - Check if value is larger than 1
COUNTIF($B3:$B$3, B3)>1
becomes
1>1
and returns FALSE. Cell B3 is not highlighted.
1.2 How to highlight duplicate values occurring the second time or more using conditional formatting in Excel
- Select the range (B3:B10)
- Press with left mouse button on the "Home" tab on the ribbon
- Press with left mouse button on "Conditional formatting"
- Press with left mouse button on "New rule..."
- Press with left mouse button on "Use a formula to determine which cells to format"
- Press with left mouse button on "Format values where this formula is true" window.
- Type COUNTIF($B3:$B$3, $B3)>1
- Press with left mouse button on "Format" button
- Go to tab "Fill"
- Pick a color
- Press with left mouse button on OK button
- Press with left mouse button on OK button again to return to Excel
1.3 Get Excel example file
highlight-duplicates-using-conditional-formatting.xls
(Excel 97-2003 Workbook *.xls)
2. Highlight the smallest duplicate number
Question: How do I highlight the smallest duplicate value in a column using conditional formatting?
Answer:
Conditional formatting formula in A2:
2.1 How to apply conditional formatting
- Select cell range
- Go to "Home" tab
- Press with left mouse button on Conditional formatting
- Press with left mouse button on "New Rule.."
- Press with left mouse button on "Use a formula to determine what cells to format"
- Copy the above conditional formatting formula to "Format values where this formula is true:"
- Press with left mouse button on Format button
- Select a formatting you like.
- Press with left mouse button on OK
- Press with left mouse button on OK
2.2 Explaining CF formula in cell A2
Step 1 - Identify duplicates
The COUNTIF function counts values based on a condition or criteria.
COUNTIF($A$2:$A$11, $A$2:$A$11)>1
becomes
COUNTIF({6;4;6;12;18;12;10;3;11;8}, {6;4;6;12;18;12;10;3;11;8})>1
becomes
{2;1;2;2;1;2;1;1;1;1}>1
and returns
{TRUE; FALSE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE}.
Step 2 - Extract duplicate numbers
The IF function uses a logical expression in order to determine which argument to return.
IF(COUNTIF($A$2:$A$11, $A$2:$A$11)>1, $A$2:$A$11, "")
becomes
IF({TRUE; FALSE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE}, $A$2:$A$11, "")
becomes
IF({TRUE; FALSE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE}, {6;4;6;12;18;12;10;3;11;8}, "")
and returns
{6;"";6;12;"";12;"";"";"";""}.
Step 3 - Identify the smallest number in array
The MIN function extracts the minimum value in a cell range or array.
MIN(IF(COUNTIF($A$2:$A$11, $A$2:$A$11)>1, $A$2:$A$11, ""))
becomes
MIN({6;"";6;12;"";12;"";"";"";""})
and returns 6.
Step 4 - Compare smallest number to current cell
MIN(IF(COUNTIF($A$2:$A$11, $A$2:$A$11)>1, $A$2:$A$11, ""))=A2
becomes
6=A2
becomes
6=6
and returns TRUE. Cell A2 is highlighted.
Get Excel *.xls file
highlight-smallest-duplicate-value-in-a-column.xls
3. Highlight more than once taken course in any given day
Answer:
Conditional formatting formula:
Explaining Conditional formatting formula
Step 1 - Count record
The next COUNTIF function counts values based on a condition or criteria.
COUNTIF($A2, $A$2:$A$35)*COUNTIF($B2, $B$2:$B$35)*COUNTIF($C2, $C$2:$C$35)
becomes
{1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 1; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 0; 0; 0; 0; 0; 1; 0; 0}*COUNTIF($B2, $B$2:$B$35)*COUNTIF($C2, $C$2:$C$35)
becomes
{1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 1; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 0; 0; 0; 0; 0; 1; 0; 0}*{1; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0}*COUNTIF($C2, $C$2:$C$35)
and returns
{1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 1; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 0; 0; 0; 0; 0; 1; 0; 0}*{1; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0}*{1; 0; 1; 0; 1; 0; 0; 0; 0; 0; 0; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 0; 1; 1; 1; 0; 0; 0; 0; 1; 0; 0; 0; 0}
Step 2 - Multiply arrays
All three arrays must return 1 in order to indicate a row as duplicate, to accomplish this we need to use AND logic. AND logic is performed using the asterisk charcater between arrays, in other words, arrays are multiplied.
COUNTIF($A2, $A$2:$A$35)*COUNTIF($B2, $B$2:$B$35)*COUNTIF($C2, $C$2:$C$35)
becomes
{1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 1; 0; 0; 0; 0; 0; 0; 0; 1; 0; 1; 0; 0; 0; 0; 0; 1; 0; 0}*{1; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 1; 0; 0; 0; 1; 0; 0; 0; 0; 0; 0; 0}*{1; 0; 1; 0; 1; 0; 0; 0; 0; 0; 0; 0; 1; 1; 0; 1; 0; 0; 1; 0; 1; 0; 1; 1; 1; 0; 0; 0; 0; 1; 0; 0; 0; 0}
and returns
{1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0}.
Step 3 - Sum numbers in array
The SUM function adds numbers in a cell range or array and returns a total.
SUM(COUNTIF($A2, $A$2:$A$35)*COUNTIF($B2, $B$2:$B$35)*COUNTIF($C2, $C$2:$C$35))
becomes
SUM({1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0})
and returns 1.
Step 4 - Check if record is a duplicate
If total is larger than 1 then we know it is a duplicate, the larger than character allows us to compare the total to a given condition, the returned value is a boolean value, TRUE or FALSE.
SUM(COUNTIF($A2, $A$2:$A$35)*COUNTIF($B2, $B$2:$B$35)*COUNTIF($C2, $C$2:$C$35))>1
becomes
1>1 and returns FALSE. Cell A2 is not highlighted.
Get Excel *.xls file
Highlight duplicate online classes using conditional formatting
4. Highlight duplicates in two columns
Question:
Answer:
The following animated image shows you two lists in column B and D.
Conditional formatting formula:
How to apply the conditional formatting formulas:
- Select cell range
- Press with left mouse button on "Home" tab on the ribbon
- Press with left mouse button on "Conditional formatting"
- Press with left mouse button on "New rule..."
- Press with left mouse button on "Use a formula to determine which cells to format"
- Press with left mouse button on "Format values where this formula is true" window.
- Type =(COUNTIF($B$3:$B3,B3)+COUNTIF($D$3:$D3,B3))>1
- Press with left mouse button on Format button
- Press with left mouse button on "Fill" tab
- Pick a color
- Press with left mouse button on OK!
- Press with left mouse button on OK!
Explaining formula
Step 1 - Check if current value B3 exists in cell range $B$3:$B3
The first argument in the COUNTIF function is a cell reference that expands downwards.
COUNTIF($B$3:$B3,B3)
Cell | COUNTIF | Result |
B3 | COUNTIF($B$3:$B3, B3) | 0 |
B4 | COUNTIF($B$3:$B4, B4) | 0 |
B5 | COUNTIF($B$3:$B5, B5) | 0 |
Step 2 - Check if current value B3 exists in cell range $D$3:$D3
The first argument in the COUNTIF function is a cell reference that expands downwards.
COUNTIF($D$3:$D3,B3)
Cell | COUNTIF | Result |
B3 | COUNTIF($D$3:$D3, B3) | 0 |
B4 | COUNTIF($D$3:$D4, B4) | 0 |
B5 | COUNTIF($D$3:$D5, B5) | 0 |
Step 3 - Add results
COUNTIF($B$3:$B3,B3)+COUNTIF($D$3:$D3,B3)
Cell | COUNTIF | Result |
B3 | COUNTIF($B$3:$B3,B3)+COUNTIF($D$3:$D3,B3) | 0 |
B4 | COUNTIF($B$3:$B4,B4)+COUNTIF($D$3:$D4,B4) | 0 |
B5 | COUNTIF($B$3:$B5,B5)+COUNTIF($D$3:$D5,B5) | 0 |
Step 4 - Check if result is larger than 1
The parentheses makes sure that the order odf calculatiuon is correct.
(COUNTIF($B$3:$B3,B3)+COUNTIF($D$3:$D3,B3))>1
becomes
(0 (zero) + 0 (zero))>1
0>1
and returns FALSE. Cell B3 is not highlighted.
Get excel *.xlsx file
Highlight duplicates in two lists using conditional formatting.xlsx
Recommended reading
Built-in conditional formatting
Data Bars Color scales IconsHighlight cells rule
Highlight cells containing stringHighlight a date occuring
Conditional Formatting Basics
Highlight unique/duplicates
Top bottom rules
Highlight top 10 valuesHighlight top 10 % values
Highlight above average values
Basic CF formulas
Working with Conditional Formatting formulasFind numbers in close proximity to a given number
Highlight empty cells
Highlight text values
Search using CF
Highlight records – multiple criteria [OR logic]Highlight records [AND logic]
Highlight records containing text strings (AND Logic)
Highlight lookup values
Unique distinct
How to highlight unique distinct valuesHighlight unique values and unique distinct values in a cell range
Highlight unique values in a filtered Excel table
Highlight unique distinct records
Duplicates
How to highlight duplicate valuesHighlight duplicates in two columns
Highlight duplicate values in a cell range
Highlight smallest duplicate number
Highlight more than once taken course in any given day
Highlight duplicates with same date, week or month
Highlight duplicate records
Highlight duplicate columns
Highlight duplicates in a filtered Excel Table
Compare
Highlight missing values between to columnsCompare two columns and highlight values in common
Compare two lists of data: Highlight common records
Compare tables: Highlight records not in both tables
How to highlight differences and common values in lists
Compare two columns and highlight differences
Min max
Highlight smallest duplicate numberHow to highlight MAX and MIN value based on month
Highlight closest number
Dates
Advanced Date Highlighting Techniques in ExcelHow to highlight MAX and MIN value based on month
Highlight odd/even months
Highlight overlapping date ranges using conditional formatting
Highlight records based on overlapping date ranges and a condition
Highlight date ranges overlapping selected record [VBA]
How to highlight weekends [Conditional Formatting]
How to highlight dates based on day of week
Highlight current date
Misc
Highlight every other rowDynamic formatting
Miscellaneous conditional formatting techniques
Highlight cells based on ranges
Highlight opposite numbers
Highlight cells based on coordinates
Excel categories
2 Responses to “How to highlight duplicate values”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
[…] has some incredible tools for highlighting cells, rows, dates, comparing data and even series in line charts. A technique using the secondary […]
[…] Highlight duplicates values […]