How to highlight duplicate values in excel with different colors
Tutor 5 (40 Reviews)
Excel Tutor
Still stuck with a Excel question
Ask this expertAnswer
Highlighting duplicates with different colors is a method that assigns a unique color to each repeated value so the duplicates stand out visually across the dataset. To highlight duplicates with multiple colors in Excel, a built-in rule is not enough because Excel applies one color per rule. A conditional formatting rule identifies duplicates, and a helper feature uses a formula to group values so each duplicate group receives a different color.
Method 1: Highlight duplicates with different colors using Conditional Formatting + Advanced Filter (Windows and Mac)
Step 1: Extract unique duplicate groups
-
Select the column that contains values.
-
Go to Data.
-
Select Advanced under the Sort & Filter group.
-
Choose Copy to another location.
-
Set List range to your data.
-
Leave Criteria range empty.
-
Set Copy to to an empty cell.
-
Tick Unique records only.
-
Press OK.
This generates a list of unique values that appear in your original column.
Step 2: Assign each unique value a color
-
Select the list of extracted unique values.
-
Go to Home → Fill Color.
-
Assign a different color to every value manually.
Excel uses 60 standard theme colors and 12 accent variants with 100% brightness, which gives more than 72 color choices.
Step 3: Apply Conditional Formatting for each colored value
-
Select the original dataset that contains duplicates.
-
Go to Home → Conditional Formatting → New Rule.
-
Select Use a formula to determine which cells to format.
-
Enter a formula that checks for a specific value, for example:
=A1="Product A"
Change the value to match the first item from your extracted list.
-
Select Format → Fill, choose the same color used in Step 2.
-
Press OK.
-
Repeat steps 1–6 for every remaining value from your extracted list, assigning its matching color.
This method highlights every duplicate group uniquely.
Windows vs. Mac differences
-
Windows: The Advanced Filter appears under Data → Sort & Filter → Advanced.
-
Mac: The Advanced Filter appears under Data → Filter → Advanced Filter.
Both platforms support the same rule types for Conditional Formatting.
How to highlight duplicates automatically with a VBA one-click macro
A VBA macro applies a different color automatically for every duplicate group without manual rules.
Steps
-
Press Alt + F11 (Windows) or Option + F11 (Mac) to open the VBA editor.
-
Select Insert → Module.
-
Paste the code below:
Sub ColorDuplicatesByGroup()
Dim rng As Range, cell As Range
Dim dict As Object, clrDict As Object
Dim nextColor As Long
Set rng = Selection
Set dict = CreateObject("Scripting.Dictionary")
Set clrDict = CreateObject("Scripting.Dictionary")
nextColor = 3
For Each cell In rng
If Not dict.exists(cell.Value) Then
dict.Add cell.Value, 1
clrDict.Add cell.Value, nextColor
nextColor = nextColor + 1
If nextColor > 56 Then nextColor = 3
End If
Next cell
For Each cell In rng
cell.Interior.ColorIndex = clrDict(cell.Value)
Next cell
End Sub
Usage
-
Select the range that contains duplicates.
-
Run the macro: Developer → Macros → ColorDuplicatesByGroup → Run.
Excel uses ColorIndex values 3 to 56, which gives over 50 distinct color options.
When to use each method
-
Manual color assignment: Needed when full control over every color is required.
-
VBA macro: Best for datasets with large volumes or when an automated workflow is required.
Get Online Tutoring or Questions answered by Experts.
You can post a question for a tutor or set up a tutoring session
Answers · 1
Why are margins not working
Answers · 1
Why is page layout not working
Answers · 1
How to print repeated rows on top in excel
Answers · 1
How to print header on each page
Answers · 1