简体   繁体   English

基于相邻单元格值的条件格式

[英]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.我尝试了另一篇帖子的建议,上面写着“=A1<B1”以突出显示绿色,反之亦然,但遗憾的是,这不起作用。 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: 回复@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:锁定行号不会影响同名范围,由于比较仍然是单元格到单元格,只有结果是 output 在整个范围内,例如:

在此处输入图像描述

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:请注意,在上图中,我们影响Column A ,这意味着条件格式的结转公式为:

'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".所以最后一列是比较一个数字与什么都没有(0),这就是为什么它一直显示为“绿色”。

This was noticed when looking at Prema's post, and the "Another attempt" in Jacob's post, which had me redo the overall.在查看 Prema 的帖子以及 Jacob 帖子中的“另一次尝试”时注意到了这一点,这让我重做了整体。 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.请注意,我们在评论部分更正了公式和受影响的范围相同,其中=A1>B1影响$A$2:$B$4的公式将显示不希望的结果。

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也许是这样 没有锁定但不同列的公式 =E1<F1 =E1>F1

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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