Reputation: 214
I am trying to change color of cell in excel if all values of a list are present in a different column.
I, also have another column with some values.
I want that color of myColumn cell should be red if all values of MyList are not present.
And it should be green if all values from MyList are present in myColumn
I tried doing it using conditional formatting
, but it changes color of cell based on single cell value.
=INDEX(B2:H2,MATCH(D2,B13:B15,0))
How can I do it based on values of a list?
Upvotes: 0
Views: 2652
Reputation: 3257
Suppose you have the following named ranges:
B2:H2
in my example;B5:B7
in my example. Please note I have named this range in the form of a Table so when I add values to this column, new values are automatically added to the named range. Set the background color of the header myColumn
to red.Then you can set the following formula as the conditional formatting rule for Cell B4
which is the header myColumn
:
=SUMPRODUCT(ISNUMBER(MATCH(MyList,myColumn,0))*1)=COLUMNS(MyList)
MATCH will compare the values in
MyList
withmyColumn
and return a number for a match and#N/A
for no match, ISNUMBER will convert the results toTRUE
orFALSE
. SUMPRODUCT will sum the results and if all values are matched it should return7
in the above example. Then compare the summed result with the expected resultCOLUMNS(MyList)
which is7
as well. If match, the formula will returnTRUE
, which will then trigger the conditional format to turn the cell background colour to green.
If I add more values to myColumn
to match MyList
:
Please note the formula only checks if all
MyList
values are present inmyColumn
but not the other way around, which means if yourmyColumn
also contains other number such as8
,9
,10
which are not inMyList
, the header will still turn green as long as it contains all values fromMyList
regardless if it has extra values or not.
Let me know if you have any questions. Cheers :)
Upvotes: 2
Reputation: 412
Check out the image:
myrow
has values that are VLOOKUP()
against mycolumn
and if isnumber()
will return TRUE, otherwise FALSE. Then do an and()
on all the resulting values and that result can be used to determine the color of the cell.
So by setting the cell's default fill color to RED, it will by default be RED, unless the following formatting rule is met, then it will be GREEN:
Upvotes: 1