Home » excel » vba – Excel Conditional Formatting For Multiple Matches

vba – Excel Conditional Formatting For Multiple Matches

Posted by: admin May 14, 2020 Leave a comment

Questions:

In this Excel, I want to set a conditional formatting such as shown in these picture attached below:

Screenshot

I have set a conditional formatting at row C such as followed to highlight the cells when it is below value / refer to remark in the attached pics :

=IF(B3="A",13,IF(B3="B",11,IF(B3="C",9)))

However, when I evaluate the conditional formatting, although I set B3 to the “C”, it will keep evaluate to the first condition , that is “A”.

What should I do to let the conditional formatting to format to its own matches; highlight row C when it is below 13 “Product A” , highlight row C when it is below 11 “Product B” , etc.

How to&Answers:

In your example select range C2:C7 and add a conditional formatting with the formula

=$C2<IF($B2="A",13,IF($B2="B",11,IF($B2="C",9,FALSE)))

As Chronocidal pointed out in his comment:
If you have not only 3 products but even more, you can use a list of products and their according “less than” values in combination with a VLOOKUP function:

=$C2<VLOOKUP($B2,$F:$G,2,FALSE)

Note that $F:$G must point to the list of products and “less than” values (see picture below):

enter image description here

This way you can easily add more products to your list without the need to adjust your formula. Also you could easily change the “less than” value for each product without adjusting your formula.