Formatting if cell value found in range

MeaclH

Board Regular
Joined
Apr 2, 2014
Messages
109
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Gday all,

I am looking for a formula that will apply conditonal formatting to a cell if the value in that cell is found elsewhere in a range.
In the sample data below for example, in rows 35,38,41,44 and so on, I would like to see if there are duplicates of any values. The one privso I can't seem to figure out is that I only want it to show duplicates for certain values.
This is a roster so there may be multiple people rostered OFF which I don't want to change the formatting of, only the shifts. I'm happy to use the codes of all 20 odd shifts in the formula if that would make it easier?

Hope that makes sense.
Cheers,
Hayden

DIGITAL ROSTER - VERSION 3.0.xlsm
N
35OFF
36
37
380530NCC
39
40
412130PL/S
42
43
441330NCC
45
46
47OFF
48
49
500530PB
51
52
53OFF
54
55
562130PB
57
58
59OFF
60
61
621330PB
63
64
65OFF
66
67
680530PL/S
69
70
71OFF
72
73
74OFF
75
76
771330BC
78
79
802130NCC
81
82
831330PL/S
84
85
86OFF
87
88
892130BC
90
91
920530BC
93
94
FN 23MAR-05APR25
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "SPDO"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "CPDO"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "BONUS"textNO
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "MATLVE"textNO
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "PATLVE"textNO
G23:T23,G26:T26,G29:T29,G32:T32,G36:T36,G39:T39,G42:T42,G45:T45,G48:T48,G51:T51,G54:T54,G57:T57,G60:T60,G63:T63,G66:T66,G69:T69,G72:T72,G75:T75,G78:T78,G81:T81,G84:T84,G87:T87,G90:T90,G93:T93,G97:T97,G100:T100,G103:T103,G106:T106,G109:T109,G113:T113Cell Valueending with "?"textNO
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "GAZETTE"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "AV"textNO
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "EDO-U"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "OFF-U"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "BLV"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "CTFN"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "CDO"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "STFN"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "SDO"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "LSL"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "A/L"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "PHC"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "OFF"textYES
G35:T94,G96:T110,G112:T126,G22:T33,G19:T19,G20,H20:T21Cell Valuecontains "EDO"textYES
G1:T3,G11:T14,G16:T17,G19:T33,G35:T94,G96:T110,G112:T126,G5:T9Expression=COLUMN()=CELL("COL")textNO
G1:T3,G11:T14,G16:T17,G19:T33,G35:T94,G96:T110,G112:T126,G5:T9Expression=G$3=TODAY()textNO
G23:T23,G26:T26,G29:T29,G32:T32,G36:T36,G39:T39,G42:T42,G45:T45,G48:T48,G51:T51,G54:T54,G57:T57,G60:T60,G63:T63,G66:T66,G69:T69,G72:T72,G75:T75,G78:T78,G81:T81,G84:T84,G87:T87,G90:T90,G93:T93,G97:T97,G100:T100,G103:T103,G106:T106,G109:T109,G113:T113Cell Valuecontains "OK"textNO
G23:T23,G26:T26,G29:T29,G32:T32,G36:T36,G39:T39,G42:T42,G45:T45,G48:T48,G51:T51,G54:T54,G57:T57,G60:T60,G63:T63,G66:T66,G69:T69,G72:T72,G75:T75,G78:T78,G81:T81,G84:T84,G87:T87,G90:T90,G93:T93,G97:T97,G100:T100,G103:T103,G106:T106,G109:T109,G113:T113Cell Valuecontains "DEC"textNO
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi Hayden,

Could you explain more simply the problem so I could wrap my head around and figure a solution?

In Range C25:C92 you want to hilight if the value OFF is present more than once?

if not, could you write the range you want to color, and something like if value x, y, z then background green, if i,j,k then font red, ...

Thanks,

Vincent
 
Upvote 0
Hi Hayden,

Could you explain more simply the problem so I could wrap my head around and figure a solution?

In Range C25:C92 you want to hilight if the value OFF is present more than once?

if not, could you write the range you want to color, and something like if value x, y, z then background green, if i,j,k then font red, ...

Thanks,

Vincent
Hi Vincent,

Thanks for taking the time to reply!

Essentially there are around 20 odd shift codes that get used day to do.
In range C25:C92 I want to have a conditional formatting rule that will apply to any shift code that appears more than once.
The hang up is that I don’t want the rule to check for multiple occurrences off particular codes used for staff on days off.
I’m wondering if the rule will need to have each shift code in it or there is another way to have it trigger.
The shift codes are the start time in 24 hour clock followed by letter identifier.
ie. 0530BC, 1330NCC.

I want to be alerted if there is a double up of shifts allocated only.

Hope this explains better.

The formatting is undecided, maybe a red background, white font.

Cheers
Hayden
 
Upvote 0
I'm still not clear on exactly what you want. If I interpret your requirement of formatting cells in the range C25:C92 where the code is a duplicate but not "OFF", then is this what you want:

Book1
C
25OFF
26
27
280530NCC
29
30
312130PL/S
32
33
341330NCC
351330NCC
36
37OFF
38
39
400530PB
41
42
43OFF
44
45
462130PB
47
48
49OFF
50
51
521330PB
53
54
55OFF
56
57
580530PL/S
590530PL/S
60
61OFF
62
63
64OFF
65
66
671330BC
68
69
702130NCC
71
720530PL/S
731330PL/S
74
75
76OFF
77
78
792130BC
80
81
820530BC
83
84
85
86
87
88
89
90
91
92
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C25:C92Expression=AND(C25<>"OFF",COUNTIF($C$25:$C$92,C25)>1)textYES
 
Upvote 1
I'm still not clear on exactly what you want. If I interpret your requirement of formatting cells in the range C25:C92 where the code is a duplicate but not "OFF", then is this what you want:

Book1
C
25OFF
26
27
280530NCC
29
30
312130PL/S
32
33
341330NCC
351330NCC
36
37OFF
38
39
400530PB
41
42
43OFF
44
45
462130PB
47
48
49OFF
50
51
521330PB
53
54
55OFF
56
57
580530PL/S
590530PL/S
60
61OFF
62
63
64OFF
65
66
671330BC
68
69
702130NCC
71
720530PL/S
731330PL/S
74
75
76OFF
77
78
792130BC
80
81
820530BC
83
84
85
86
87
88
89
90
91
92
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C25:C92Expression=AND(C25<>"OFF",COUNTIF($C$25:$C$92,C25)>1)textYES
Hi Kevin, yes this is pretty much spot on. Can I add more values that aren’t to be counted as multiples? I assume just separated by a comma?

Thanks so much for your help!

Cheers
Hayden
 
Upvote 0
Could you list them on a table on the same sheet? I think the CF formula could be made a lot simpler if you could.
 
Upvote 0
Hi @MeaclH
I am looking for a formula that will apply conditonal formatting to a cell if the value in that cell is found elsewhere in a range.
I see you're in good hands with Kevin taking care of your request regarding CFRs to address duplicates with custom exclusions.

I was looking at your request earlier and noticed you have a lot of CFR's; many using identical formatting.
I use CFR's alot in some cases, and wanted to share some advice on how to combine some of them... if interested.

For example, you have some Orange Fill being applied to the same ranges that contain either of the following text: BLV, CDO, SDO, CPDO, SPDO, CTFN, STFN
All of these could be combined using the COUNTIF function. I've used this many times in several workbooks.

Below I'm providing both a Long Version and a Short Version for the following: Orange Fill, Green Fille, Yellow Fill and No Formatting.
You can view and grab the formulas from the Mini Sheets below...

Note: I'm using wildcards (*) becasue that's what "contains" does by default.
CONSIDER: If you use...
  • PDO instead of CPDO & SPDO, will this wind up formatting anything else that shouldn't be? If not, then I would use the substitute.
  • TFN instead of CTFN & STFN...?
Criteria used for both versions:
  • Orange Fill (Long Version) using: BLV, CDO, SDO, CPDO, SPDO, CTFN, STFN
  • Orange Fill (Short Version) using: BLV, CDO, SDO, ~PDO,~TFN
  • Green Fill (Long Version) using: EDO, EDO-U
  • Green Fill (Short Version) using just EDO considering it will format both criteria anyway.
  • Yellow Fill (Long Version) using: OFF, OFF-U
  • Yellow Fill (Short Version) using just OFF considering it will format both criteria anyway.
  • No Formatting (Long Version) using: A/L, BONUS, GAZETTE, LSL, MATLVE, PATLVE, PHC
  • No Formatting (Short Version) using: nothing :)
Personally, I don't think you need to use the No Formatting CFRs. They are not being used to apply any conditional formatting and appear to have no effect on the cells that contain those various string values. Is there some other formatting taking place where these are removing formatting? Just curious.

Regarding Ranges the formatting is being applied to:

You technically have four different ranges that your formatting is being applied to for the CFR's I've mentioned above.
I also noticed you have a break in your top range (image). Those marching ants show 4 seperate selections... thus leaving G21 out of the range.

1738141021900.png

Your current range:
Excel Formula:
=$G$35:$T$94,$G$96:$T$110,$G$112:$T$126,$G$22:$T$33,$G$19:$T19,$G$20,$H$20:$T$21
The fixed range:
Excel Formula:
=$G$19:$T$33,$G$35:$T$94,$G$96:$T$110,$G$112:$T$126

To test the CFR's I'm proposing, I created some sample data using a list of your criteria, and applying it to your top range randomly using the following formula.
W19:W36 is a list of your criteria.
Excel Formula:
=INDEX($W$19:$W$36,RANDBETWEEN(1,ROWS($W$19:$W$36)),1)

This 1st Example is using all of the Long Versions of the CFRs:
BLV, CDO, SDO, CPDO, SPDO, CTFN, STFN | EDO, EDO-U | OFF, OFF-U | A/L, BONUS, GAZETTE, LSL, MATLVE, PATLVE, PHC

VBA Testing.xlsm
GHIJKLMNOPQRST
19OFF-ULSLSTFNBLVBLVOFF-UCPDOSPDOA/LOFF-UOFFOFF-USPDOPATLVE
20SPDOBLVOFFEDO-USDOBLVA/LBLVOFF-UOFFEDO-USTFNEDO-USPDO
21OFF-UA/LBLVCTFNEDOSPDOEDOMATLVEBLVBLVBONUSPHCA/LEDO
22CDOCDOA/LCTFNLSLBONUSA/LCTFNLSLOFF-UMATLVEOFF-USPDOSTFN
23BONUSCPDOEDOBLVBONUSLSLCTFNOFFLSLPATLVEEDOSPDOCDOEDO
24CDOPATLVEMATLVESPDOPHCSPDOEDOA/LEDO-UOFF-USDOCPDOEDO-ULSL
25PHCMATLVECPDOCDOLSLCPDOCPDOLSLCPDOBLVSPDOBONUSOFFPHC
26PATLVEOFFA/LCTFNSTFNBLVOFFBONUSMATLVEMATLVEBLVA/LCDOA/L
27STFNEDO-UCPDOOFF-UCTFNMATLVEOFF-ULSLEDO-UEDO-UPATLVEOFFPHCOFF-U
28SDOCTFNSTFNA/LGAZETTEPATLVEOFF-USTFNGAZETTEMATLVECTFNCDOEDOCTFN
29SPDOEDOCTFNGAZETTECPDOEDO-USDOPATLVECDOGAZETTECPDOA/LMATLVEOFF-U
30GAZETTESTFNSPDOCTFNCTFNCPDOGAZETTEPHCPHCLSLPATLVEBONUSEDO-UA/L
31EDOMATLVEBONUSPHCMATLVEBLVCPDOBONUSSDOBONUSOFFSTFNEDO-UCDO
32BLVLSLPATLVECDOCPDOLSLGAZETTEBLVLSLLSLSTFNSDOLSLLSL
33EDO-UGAZETTECTFNCPDOGAZETTECTFNMATLVESTFNCTFNCPDOSPDOLSLMATLVESTFN
CountUnique
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G19:T33,G35:T94,G96:T110,G112:T126Expression=OR(COUNTIF(G19,"*BLV*"), COUNTIF(G19,"*CDO*"), COUNTIF(G19,"*SDO*"), COUNTIF(G19,"*PDO*"), COUNTIF(G19,"*TFN*"))textNO
G19:T33,G35:T94,G96:T110,G112:T126Expression=OR(COUNTIF(G19,"*EDO*"), COUNTIF(G19,"*EDO-U*"))textNO
G19:T33,G35:T94,G96:T110,G112:T126Expression=OR(COUNTIF(G19,"*OFF*"), COUNTIF(G19,"*OFF-U*"))textNO
G19:T33,G35:T94,G96:T110,G112:T126Expression=OR(COUNTIF(G19,"*A/L*"), COUNTIF(G19,"*BONUS*"), COUNTIF(G19,"*GAZETTE*"), COUNTIF(G19,"*LSL*"), COUNTIF(G19,"*MATLVE*"), COUNTIF(G19,"*PATLVE*"), COUNTIF(G19,"*PHC*"))textNO


This 2nd Example is using all of the Short Versions of the CFRs:
BLV, CDO, SDO, PDO, TFN | EDO | OFF | nothing

VBA Testing.xlsm
GHIJKLMNOPQRST
19OFF-ULSLSTFNBLVBLVOFF-UCPDOSPDOA/LOFF-UOFFOFF-USPDOPATLVE
20SPDOBLVOFFEDO-USDOBLVA/LBLVOFF-UOFFEDO-USTFNEDO-USPDO
21OFF-UA/LBLVCTFNEDOSPDOEDOMATLVEBLVBLVBONUSPHCA/LEDO
22CDOCDOA/LCTFNLSLBONUSA/LCTFNLSLOFF-UMATLVEOFF-USPDOSTFN
23BONUSCPDOEDOBLVBONUSLSLCTFNOFFLSLPATLVEEDOSPDOCDOEDO
24CDOPATLVEMATLVESPDOPHCSPDOEDOA/LEDO-UOFF-USDOCPDOEDO-ULSL
25PHCMATLVECPDOCDOLSLCPDOCPDOLSLCPDOBLVSPDOBONUSOFFPHC
26PATLVEOFFA/LCTFNSTFNBLVOFFBONUSMATLVEMATLVEBLVA/LCDOA/L
27STFNEDO-UCPDOOFF-UCTFNMATLVEOFF-ULSLEDO-UEDO-UPATLVEOFFPHCOFF-U
28SDOCTFNSTFNA/LGAZETTEPATLVEOFF-USTFNGAZETTEMATLVECTFNCDOEDOCTFN
29SPDOEDOCTFNGAZETTECPDOEDO-USDOPATLVECDOGAZETTECPDOA/LMATLVEOFF-U
30GAZETTESTFNSPDOCTFNCTFNCPDOGAZETTEPHCPHCLSLPATLVEBONUSEDO-UA/L
31EDOMATLVEBONUSPHCMATLVEBLVCPDOBONUSSDOBONUSOFFSTFNEDO-UCDO
32BLVLSLPATLVECDOCPDOLSLGAZETTEBLVLSLLSLSTFNSDOLSLLSL
33EDO-UGAZETTECTFNCPDOGAZETTECTFNMATLVESTFNCTFNCPDOSPDOLSLMATLVESTFN
CountUnique
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G19:T33,G35:T94,G96:T110,G112:T126Expression=OR(COUNTIF(G19,"*BLV*"), COUNTIF(G19,"*CDO*"), COUNTIF(G19,"*SDO*"), COUNTIF(G19,"*PDO*"), COUNTIF(G19,"*TFN*"))textNO
G19:T33,G35:T94,G96:T110,G112:T126Expression=COUNTIF(G19,"*EDO*")textNO
G19:T33,G35:T94,G96:T110,G112:T126Expression=COUNTIF(G19,"*OFF*")textNO
 
Last edited:
Upvote 0
Could you list them on a table on the same sheet? I think the CF formula could be made a lot simpler if you could.
 
Upvote 0

Forum statistics

Threads
1,226,059
Messages
6,188,634
Members
453,487
Latest member
LZ_Code

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