Home » excel » excel – Highlight Cells Based on If Function

excel – Highlight Cells Based on If Function

Posted by: admin May 14, 2020 Leave a comment


Is there a VBA code or excel function which can highlight the A cell based on the value of the corresponding B cell. For example if the number in row A is larger than B then highlight the A cell green and orange if B is larger. As shown

enter image description here

Is there some option to do this in conditional formatting? Or even a VBA code?

How to&Answers:

Add something like this using conditional formatting:


^ =A1<A2 and =A1>A2.

And then select the Format Painter and drag it along:



No need manual formatting. Just use full range containing data in Apply To section.

As per your screenshot.

  1. Select B1:G2 cells.
  2. Select Conditional Formatting under style section. Then click on New Rule.
    enter image description here

  3. Select Use a formula to determine which cells to format.

enter image description here

  1. Use formula like below screenshot.



enter image description here


enter image description here