Conditional format formula to look for duplicates in multiple columns

sonosite

New Member
Joined
Nov 24, 2014
Messages
15
I am using excel for making out a shift schedule for my company. How do I create a conditional format formula to look for duplicate initials in multiple columns and to repeat the assessment independently for many more rows?

Additionally, the formula would only look at the first 2 characters in a cell to check for duplication.


Example of data


Site1 Site2 Site3 Site4 Site5
1/1/2015 AA BB CC DD EE
1/2/2015 BB CC BB AA EE
1/3/2015 CC CC CC BB AA
1/4/2015 BB CC BB-t AA EE


First row has unique initials of AA to EE. There is no error with this row.
Second row has duplicated BB in two columns that I want the formula to highlight.
Third row has duplicated CC in three columns that I want the formula to highlight.
Fourth row has duplicated BB in two columns when you look at the first two characters in the cell that I want the formula to highlight.


Since this is a day by day basis, creating a conditional formating for each row individually would be unrealistic. The formula needs to look at every single row independently in the spreadsheet.

Thanks.


 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Here's a solution I came up with if you want to try it.

I selected the data below starting with A1 and ending in F2 so that A1 is the cell that is the active cell.

I then go to conditional formatting and choose to use a formula to decide which cells to conditionally format.

I then enter the formula you see repeated below, but only one time is necessary.

=COUNTIF(1:1,A1)>1

When the cells are are selected as I described above and the formula is entered as you see if will highlight the duplicate cells.

There is one caveat in this solution, the formula creates an intentional circular reference, I don't know of another formula to do what you want. Maybe someone else does.

You have to allow iterations in order for the formula to work with the circular reference.

I have Excel 2010 and I go to file, options, formula and then check the box that says allow iterative calculations.

I have the box for maximum iterations set to 1000 and this seems to be plenty.

If you do not have Excel 2010 you can try searching help for iterative calculations, iterations, or maybe circular references on your copy of Excel to see where the setting is.

The conditional formatting doesn't show up on my computer when I save my post, but it is there and it's highlighting the duplicates in each row.


Sheet14


*ABCDEF
EEBBEEDDEEFF
KKKKGGAALLEE

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
[TD="bgcolor: #cacaca, align: center"]1[/TD]

[TD="bgcolor: #cacaca, align: center"]2[/TD]

</tbody>

Conditional formatting
CellNr.: / ConditionFormat
A11. / Formula is =COUNTIF(1:1,A1)>1

<tbody>
[TD="bgcolor: #ffff00"]Abc

<tbody>
B11. / Formula is =COUNTIF(1:1,A1)>1
C11. / Formula is =COUNTIF(1:1,A1)>1
D11. / Formula is =COUNTIF(1:1,A1)>1
E11. / Formula is =COUNTIF(1:1,A1)>1
F11. / Formula is =COUNTIF(1:1,A1)>1
A21. / Formula is =COUNTIF(1:1,A1)>1
B21. / Formula is =COUNTIF(1:1,A1)>1
C21. / Formula is =COUNTIF(1:1,A1)>1
D21. / Formula is =COUNTIF(1:1,A1)>1
E21. / Formula is =COUNTIF(1:1,A1)>1
F21. / Formula is =COUNTIF(1:1,A1)>1

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

[TD="bgcolor: #ffff00"]Abc[/TD]

</tbody>
[/TD]

</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Last edited:
Upvote 0
Maybe something like this


[Table="class: grid"][tr][td] [/td][td]
A
[/td][td]
B
[/td][td]
C
[/td][td]
D
[/td][td]
E
[/td][td]
F
[/td][/tr]
[tr][td]
1
[/td][td] [/td][td]
Site1​
[/td][td]
Site2​
[/td][td]
Site3​
[/td][td]
Site4​
[/td][td]
Site5​
[/td][/tr]


[tr][td]
2
[/td][td]
01/01/2015​
[/td][td]
AA​
[/td][td]
BB​
[/td][td]
CC​
[/td][td]
DD​
[/td][td]
EE​
[/td][/tr]


[tr][td]
3
[/td][td]
01/02/2015​
[/td][td]
BB​
[/td][td]
CC​
[/td][td]
BB​
[/td][td]
AA​
[/td][td]
EE​
[/td][/tr]


[tr][td]
4
[/td][td]
01/03/2015​
[/td][td]
CC​
[/td][td]
CC​
[/td][td]
CC​
[/td][td]
BB​
[/td][td]
AA​
[/td][/tr]


[tr][td]
5
[/td][td]
01/04/2015​
[/td][td]
BB​
[/td][td]
CC​
[/td][td]
BB-t​
[/td][td]
AA​
[/td][td]
EE​
[/td][/tr]
[/table]


Select B2:F5 being B2 the active cell (the one that is not shaded after the selection)

Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format

insert this formula
=SUMPRODUCT(--(LEFT($B2:$F2,2)=LEFT(B2,2)))>1

pick the format you want (Font color = red in the example above)

Hope this helps

M.
 
Upvote 0
I take back what I said about the circular reference.
If the formula was in one of the actual cells it would cause a circular reference, it works fine in conditional formatting and you don't have to select the iterations.
 
Upvote 0
Oh, wow.... Thank you so much. It works! However, is there a way to conditionally avoid considering multiple blank cells as "duplicates" if I use background color formating?

Maybe something like this


[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[TD]
F
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD][/TD]
[TD]
Site1​
[/TD]
[TD]
Site2​
[/TD]
[TD]
Site3​
[/TD]
[TD]
Site4​
[/TD]
[TD]
Site5​
[/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]
01/01/2015​
[/TD]
[TD]
AA​
[/TD]
[TD]
BB​
[/TD]
[TD]
CC​
[/TD]
[TD]
DD​
[/TD]
[TD]
EE​
[/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]
01/02/2015​
[/TD]
[TD]
BB​
[/TD]
[TD]
CC​
[/TD]
[TD]
BB​
[/TD]
[TD]
AA​
[/TD]
[TD]
EE​
[/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]
01/03/2015​
[/TD]
[TD]
CC​
[/TD]
[TD]
CC​
[/TD]
[TD]
CC​
[/TD]
[TD]
BB​
[/TD]
[TD]
AA​
[/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]
01/04/2015​
[/TD]
[TD]
BB​
[/TD]
[TD]
CC​
[/TD]
[TD]
BB-t​
[/TD]
[TD]
AA​
[/TD]
[TD]
EE​
[/TD]
[/TR]
</tbody>[/TABLE]


Select B2:F5 being B2 the active cell (the one that is not shaded after the selection)

Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format

insert this formula
=SUMPRODUCT(--(LEFT($B2:$F2,2)=LEFT(B2,2)))>1

pick the format you want (Font color = red in the example above)

Hope this helps

M.
 
Upvote 0
Oh, wow.... Thank you so much. It works! However, is there a way to conditionally avoid considering multiple blank cells as "duplicates" if I use background color formating?

Try this formula
=AND(B2<>"",SUMPRODUCT(--(LEFT($B2:$F2,2)=LEFT(B2,2)))>1)

M.
 
Upvote 0
Since this formula worked perfectly, I would want to ask another conditional formating question, but now in the vertical direction. I don't know how to create one new large table sample, so I am copying/pasting your sample multiple times. Consider it as one big spreadsheet with multiple rows.

How do I create a conditional formula that looks in a single column and highlights if any initials are repeated more than 4 times (>4)?

Sample below:
Column B: no repeated initals more than 4 times. No highlight occurs for column B
Column C: AA is repeated 5 times. Conditional formating should highlight AA
Column D: Conditional formating should only look at the first 2 characters in a cell for repeat. AA is repeated 6 times and is highlighted
Column E: AA is repeated 5 times. BB is repeated 5 times. There are also 5 blank cells. Conditional formating should highlight AA and BB only

Note: for this discussion, I don't care if initials are repeated on the same row. You have solved that already!
[TABLE="class: cms_table_grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[TD]

[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD][/TD]
[TD]Site1
[/TD]
[TD]Site2
[/TD]
[TD]Site3
[/TD]
[TD]Site4
[/TD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TD]
11
[/TD]
[TD]
01/10/2015​
[/TD]
[TD]DD
[/TD]
[TD]DD
[/TD]
[TD]CC
[/TD]
[TD]BB
[/TD]
[TD]

[/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="class: cms_table_grid"]
<tbody>[TR]
[TD]12[/TD]
[TD]
01/11/2015
[/TD]
[TD]
EE
[/TD]
[TD]
EE
[/TD]
[TD]
EE
[/TD]
[TD]
BB
[/TD]
[TD]

[/TD]
[/TR]
[TR]
[TD]
13
[/TD]
[TD]
01/12/2015
[/TD]
[TD]EE
[/TD]
[TD]EE
[/TD]
[TD]EE
[/TD]
[TD]

[/TD]
[TD]

[/TD]
[/TR]
[TR]
[TD]
14
[/TD]
[TD]
01/13/2015​
[/TD]
[TD]EE
[/TD]
[TD]EE
[/TD]
[TD]EE
[/TD]
[TD]BB
[/TD]
[TD]

[/TD]
[/TR]
[TR]
[TD]
15
[/TD]
[TD]
01/14/2015​
[/TD]
[TD]FF
[/TD]
[TD]FF
[/TD]
[TD]FF
[/TD]
[TD]

[/TD]
[TD]

[/TD]
[/TR]
[TR]
[TD]
16
[/TD]
[TD]
01/15/2015​
[/TD]
[TD]FF
[/TD]
[TD]FF
[/TD]
[TD]FF
[/TD]
[TD]

[/TD]
[TD]

[/TD]
[/TR]
[TR]
[TD]
17
[/TD]
[TD]
01/16/2015​
[/TD]
[TD]FF
[/TD]
[TD]FF
[/TD]
[TD]FF
[/TD]
[TD]

[/TD]
[TD]

[/TD]
[/TR]
</tbody>[/TABLE]



 
Upvote 0
.. another option for the original question might be
=AND(B2<>"",COUNTIF($B2:$F2,LEFT(B2,2)&"*")>1)
 
Upvote 0
Since this formula worked perfectly, I would want to ask another conditional formating question, but now in the vertical direction. I don't know how to create one new large table sample, so I am copying/pasting your sample multiple times. Consider it as one big spreadsheet with multiple rows.

How do I create a conditional formula that looks in a single column and highlights if any initials are repeated more than 4 times (>4)?
Excel Workbook
BCDE
1Site1Site2Site3Site4
2AAAAAAAA
3AA-tAAAA-t
4AAAAAAAA
5AA-rAAAA-rAA
6BBBBAAAA
7BBBBAAAA
8BBBBBB
9CCAACCBB
10CCCCCCBB
11DDDDCCBB
12EEEEEEBB
13EEEEEE
14EEEEEEBB
15FFFFFF
16FFFFFF
17FFFFFF
18
CF Columns
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B21. / Formula is =AND(B2<>"",COUNTIF(B$2:B$1000,LEFT(B2,2)&"*")>4)Abc
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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