简体   繁体   中英

Conditional formatting based on value of adjacent cell

I have a bunch of information that I am trying to highlight based on the value of the information in the cell to the right of the current cell. I want it to be highlighted green if the value is greater than the value to the right, and red if lesser than the value to the right.

I have so far been unsuccessful. I tried a recommendation from another post that said "=A1<B1" to highlight green and vice versa, but sadly, that did not work. A screenshot of what that did can be seen here: 基于 =A1<B1 的突出显示数据,反之亦然

Locking my columns gives me this result: 锁定列

Another attempt: 尝试使用公式

Response to @Cyril: 回复@Cyril

I hope you are able to help. Thanks in advance!

When using conditional formatting, you need to be very careful about what gets fixed.

This formula, from your post, will affect the entire ranged acted upon:

"=A1<B1"

If you want to affect an entire row, then you need to lock the column in your formula, allowing the row number to be dynamic, eg:

"=$A1<$B1"

在此处输入图像描述

Locking a row number does not affect the range the same name, due to the comparison still being cell to cell, only the result is output over an entire range, eg:

在此处输入图像描述

If you want to have a cell:cell comparison over multiple columns, you will need to have multiple conditional formatting:

在此处输入图像描述


Edit :

Turns out we were all making the same typographical issue in our responses.

A single formula can work where we use the correct range references:

在此处输入图像描述

Note that in the above pictures, we had affected Column A , meaning that the carried-forward formula for conditional formatting was:

'For column A:
=A1>B1
'For column B
=B1>C1

So the last column is comparing a number versus nothing (0), which is why it kept showing up as all "green".

This was noticed when looking at Prema's post, and the "Another attempt" in Jacob's post, which had me redo the overall. Note that we corrected in the comments section the formula and affected range being the same, where a formula for =A1>B1 affecting $A$2:$B$4 will show an undesired result.

I'm not sure if you can realise it with just one formula: in my opinion you need one formula for the green colour and one for the red colour. I've done it in the following way: (according to the Chinese, a drawing says more than a thousand words:-) )

在此处输入图像描述

Maybe like this The formula without locking but different columns =E1<F1 =E1>F1

在此处输入图像描述

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