简体   繁体   中英

Conditional formatting based on adjacent cells value

I am trying to keep track of budget, what I've got if a spreadsheet with months of the year along with a name and how much spare cash is left at the end of the month like so;

| Person | Jan | Feb | March |
|--------|-----|-----|-------|
| Joe    | £1  |£10  |£8     |
| Tess   | £5  |£1   |£8     |
| Tim    | £3  |£8   |£6     |
| Jane   | £8  |£1   |£7     |

What I want to do;

I want to be able to have a formula for the conditional formatting which will colour the cell to the right red / green on if the value is greater than or less than the cell to the left. In the example I gave above the first February cell is greater than the first January cell so that would be green, the first March cell is lower than the first February cell so that would be red. I have used the below to achieve this but you need to do that for every single cell and that's very time consuming and I was hoping I could write one formula that would do all cells;

On Joes Feb I would have the conditional code

=B2<A2

And

=B2>A2

Ideally I would just have two sets of codes, one for negative and one for positive that would do all cells.

Thanks for the help.

Assuming your data is as displayed, with header "Person" in cell A1 , Jan in cell B1 , and "Joe" in A2 .

Select C2 .

Highlight range C2:D5

Click Conditional Formatting => Manage Rules

Click New Rule , select "Use a formula to determine which cells to format"

Use this formula: =c2>b2 and set your format to Green.

Click OK .

Click New Rule , select "Use a formula to determine which cells to format"

Use this formula: =c2<b2 and set your format to Red.

Click OK . Click Ok . Click OK .

That should do it ... by selecting the range first, your conditional formatting applies to the entire range. By using formulas that reference cells without "$", the logic will be applied to each cell using the formula as a relative reference (ie relative to each cell in the range).

If this doesn't quite do what you want/need, please clarify what's not working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM