How to highlight duplicates different colors
Tutor 5 (97 Reviews)
Excel Tutor
Still stuck with a Excel question
Ask this expertAnswer
To highlight duplicates in different colors in Excel, use Conditional Formatting with multiple rules or manual formatting after identifying duplicates. Excel provides built-in options to mark duplicate values automatically, and you can customize colors for first occurrences versus subsequent duplicates or assign unique colors to different duplicate groups.
Using Conditional Formatting for Two-Color Duplicate Highlighting
Conditional Formatting applies colors to cells based on rules you define.
- Select the range containing your data
- Navigate to Home tab > Conditional Formatting > Highlight Cells Rules > Duplicate Values
- Choose your desired formatting color from the dropdown menu
- Click OK to apply the formatting
This method highlights all duplicate values in one color. To create a two-tier system where first occurrences and subsequent duplicates receive different colors:
- Select your data range
- Go to Home tab > Conditional Formatting > New Rule
- Select "Use a formula to determine which cells to format"
- Enter the formula:
=COUNTIF($A$1:$A1,$A1)=1(adjust range references to match your data) - Click Format button, choose your color for first occurrences, click OK
- Click OK again to apply the rule
- Create a second rule by clicking Conditional Formatting > New Rule
- Select "Use a formula to determine which cells to format"
- Enter the formula:
=COUNTIF($A$1:$A1,$A1)>1 - Click Format button, choose a different color for subsequent duplicates, click OK
- Click OK to complete
Highlighting Each Duplicate Set with Different Colors
Excel does not include a native feature to automatically assign unique colors to each group of duplicates. You can achieve this through manual formatting or VBA macros.
Manual Method:
- Select your data range
- Go to Home tab > Conditional Formatting > Highlight Cells Rules > Duplicate Values
- Apply initial formatting to identify all duplicates
- Sort your data (Data tab > Sort) to group duplicate values together
- Select the first group of duplicates manually
- Apply a fill color from Home tab > Font group > Fill Color
- Repeat steps 5-6 for each subsequent duplicate group with different colors
VBA Method:
- Press Alt+F11 (Windows) or Fn+Option+F11 (Mac) to open Visual Basic Editor
- Go to Insert > Module
- Paste the following code:
Sub HighlightDuplicatesMultiColor()
Dim rng As Range
Dim cell As Range
Dim dict As Object
Dim colorIndex As Long
Dim colors As Variant
Set dict = CreateObject("Scripting.Dictionary")
colors = Array(RGB(255, 199, 206), RGB(255, 235, 156), RGB(198, 224, 180), _
RGB(186, 202, 233), RGB(221, 235, 247), RGB(230, 185, 184))
colorIndex = 0
Set rng = Selection
For Each cell In rng
If WorksheetFunction.CountIf(rng, cell.Value) > 1 Then
If Not dict.Exists(cell.Value) Then
dict.Add cell.Value, colors(colorIndex Mod 6)
colorIndex = colorIndex + 1
End If
cell.Interior.Color = dict(cell.Value)
End If
Next cell
End Sub
- Close the Visual Basic Editor
- Select your data range
- Press Alt+F8 (Windows) or Fn+Option+F8 (Mac)
- Select "HighlightDuplicatesMultiColor" from the macro list
- Click Run
This macro assigns a different color from a predefined palette to each unique duplicate value group.
Creating Advanced Color Rules for Duplicates
You can combine multiple conditional formatting rules to create sophisticated color schemes:
- Select your data range
- Go to Home tab > Conditional Formatting > Manage Rules
- Click New Rule for each color condition you want to add
- Use formulas with COUNTIF to target specific duplicate patterns
- Assign priority by moving rules up or down using arrows in the Manage Rules dialog
- Click OK when all rules are configured
Rules with higher priority (lower number) override rules with lower priority when multiple conditions match the same cell.
Using Helper Columns for Color-Coded Duplicate Tracking
Helper columns provide precise control over which duplicates receive specific colors.
- Create a new column adjacent to your data
- Enter a formula to assign group numbers:
- Copy the formula down the column
- Select your original data range
- Go to Home tab > Conditional Formatting > New Rule
- Choose "Use a formula to determine which cells to format"
- Create separate rules for each group number with different colors
Use formulas like =$B1=1, =$B1=2, etc., for each rule
This approach assigns sequential numbers to duplicate groups, enabling precise color application through conditional formatting rules.
Removing Duplicate Highlighting
To clear conditional formatting colors:
- Select the formatted range
- Go to Home tab > Conditional Formatting > Clear Rules
- Choose "Clear Rules from Selected Cells" or "Clear Rules from Entire Sheet"
To remove manual fill colors:
- Select the colored cells
- Go to Home tab > Font group > Fill Color
- Select "No Fill"
Get Online Tutoring or Questions answered by Experts.
You can post a question for a tutor or set up a tutoring session
Answers · 1
What is the formula to highlight duplicate values
Answers · 1
What is the formula to remove duplicates
Answers · 1
How to delete duplicate values in excel
Answers · 1
How to delete duplicate rows based on one column
Answers · 1