highlight duplicate values, but with a different color for each unique value

smking204

New Member
Joined
Jan 28, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Title should be pretty self-explanatory. Seems like something I could figure out, I just don't have the time...

So, like, if my list is: 1, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 9, 9, I want the 3's highlighted one color, the 7's a different color, and the 9's a third color.

I'm so demanding, I know.

Thanks in advance, y'all!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Title should be pretty self-explanatory. Seems like something I could figure out, I just don't have the time...

So, like, if my list is: 1, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 9, 9, I want the 3's highlighted one color, the 7's a different color, and the 9's a third color.

I'm so demanding, I know.

Thanks in advance, y'all!
How many possible numbers can there be? For CF, you will have to have a separate rule for each number. VBA might be a better option if there are many possible numbers, but I can't think of it off the top of my head.
 
Upvote 0
How many possible numbers can there be? For CF, you will have to have a separate rule for each number. VBA might be a better option if there are many possible numbers, but I can't think of it off the top of my head.
thanks, yes, CF should be fine. 7-10 iterations of a rule should be sufficient.
 
Upvote 0
Okay, well if this looks like what you want, then duplicate one of the rules for each other number you could possibly have:
Book1
A
11
22
33
43
54
65
76
87
97
107
118
129
139
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A13Expression=AND($A1=9,COUNTIF($A$1:$A1,9)>1)textNO
A1:A13Expression=AND($A1=7,COUNTIF($A$1:$A1,7)>1)textNO
A1:A13Expression=AND($A1=3,COUNTIF($A$1:$A1,3)>1)textNO
 
Upvote 0
Okay, well if this looks like what you want, then duplicate one of the rules for each other number you could possibly have:
Book1
A
11
22
33
43
54
65
76
87
97
107
118
129
139
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:A13Expression=AND($A1=9,COUNTIF($A$1:$A1,9)>1)textNO
A1:A13Expression=AND($A1=7,COUNTIF($A$1:$A1,7)>1)textNO
A1:A13Expression=AND($A1=3,COUNTIF($A$1:$A1,3)>1)textNO
hmmm ok. Let me tighten up my question. The values in the original list could be anything (usually a 4 digit number). The list will only be about 20 items or so at most, and I will only expect 7-10 of those, at most, to have duplicates.

I'm aiming for the formula to be like, "if any values appear more than once, filter out a sublist of those values, then assign a format to the nth value (using MATCH??) in that sublist." I could create 7 different formulas for n. Does that make sense? I poked at it, and just don't have the time right now...
 
Upvote 0
Okay, maybe something like this then. Assuming your IDs/numbers are in col A, use the formula in col C to identify the duplicates in col A.

Cols D:E are just for reference on how the CF rules are working. Each row of the duplicate ID col is what determines the color based on what # MATCH returns.
Book1
ABCDE
1List of IDsDuplicate IDsColor LegendID to Duplicate Match
2171214
3131322
4131632
5191746
6121851
711196#N/A
81875
9148#N/A
101895
1116103
12196
13132
14121
15163
16174
17174
18121
19196
20196
2110#N/A
Sheet1
Cell Formulas
RangeFormula
C2:C7C2=SORT(UNIQUE(FILTER(A2:A21,COUNTIF(A2:A21,A2:A21)>1)))
E2:E21E2=MATCH(A2,$C$2#,0)
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A21Expression=MATCH(A2,$C$2#,0)=10textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=9textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=8textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=7textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=6textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=5textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=4textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=3textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=2textNO
A2:A21Expression=MATCH(A2,$C$2#,0)=1textNO


I will adjust the CF formula if you only want a specific duplicate to be highlighted. IE: all duplicates except the first unique instance of each number.
 
Upvote 0
Solution
Yes, this seems to give me what I need! I embedded the SORT within the MATCH, and set it equal to n, like this:

=MATCH(A2,SORT(UNIQUE(FILTER($A$2:$A$35,COUNTIF($A$2:$A$35,$A$2:$A$35)>1))),0)=1

I wasn't sure how to use the COUNTIF in that way, I'll have to study that later.

Curious if the SORT is unnecessary here...?

And can you point me to a resource on what the # is doing in your MATCH formula? I've never seen that. Is that like a "length of" or something?

Thanks a bunch!
 
Upvote 0
Yes, the SORT is unnecessary included in the CF formula like that. I was using it for readability on the sheet. And the # is referring to the spilled range of the formula: '=SORT(UNIQUE(FILTER(A2:A21,COUNTIF(A2:A21,A2:A21)>1)))'

You're welcome, and happy to help.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top