Search code examples
google-sheetsbooleanconditional-statementsconditional-formattingboolean-logic

Conditional formatting: color a cell based on a comparison with another cell


Consider the following table in Google Sheets:

       |   A     |   B   |  C
   ----+---------+-------+--------
    1  | product | price | target
    2  | apple   | 5     | 6
    3  | pear    | 7     | 4 
    4  | banana  | 2     | 2

What I am looking to do is applying some conditional formatting, but I cannot figure this one out so I hope somene can help me.

What I want to achieve:

  • For every product, check the price against the target
  • If the current price is ** equal to** or under the target, I would like to target price to color Green. This would be the case for cells C2 and C4
  • If the current price is above the target price, I would like the target price to color Red. This is the case for C3.

Is there any way to achieve this? Whenever a target turns green, it means that for me, this product is in the buying zone and I should look into it more closely.

Any help is greatly appreciated!


Solution

  • green:

    =((C2=B2)+(B2<C2))*(C2<>"")
    

    red:

    =B2>C2
    

    enter image description here