简体   繁体   English

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

[英](Excel) Conditional Formatting based on Adjacent Cell Value

I'm trying to apply conditional formatting in Excel on a range of cells, based on the adjacent cell's value, to achieve something like this:我正在尝试根据相邻单元格的值在 Excel 中对一系列单元格应用条件格式,以实现如下目标:

费用条件格式

The goal is to highlight values in Column B (Actual Expense) red if the value is greater than it's adjacent value in column C (Expected Expense).如果值大于 C 列(预期支出)中的相邻值,则目标是将 B 列(实际支出)中的值突出显示为红色。 I've followed a number of tutorials that said to apply conditional formatting by selecting Conditional Formatting>New Rules>Use a Formula to Determine Which Cells to Format then applying a rule =$B4>$C4 which would format the 'Actual' cell red if it were greater than the 'Expected' cell.我遵循了许多教程,这些教程说通过选择条件格式>新规则>使用公式来确定要格式化的单元格然后应用规则 =$B4>$C4 将“实际”单元格格式化为红色来应用条件格式如果它大于“预期”单元格。 This works great for one cell, but not so well when I attempt to apply this to a range of cells.这适用于一个单元格,但当我尝试将其应用于一系列单元格时效果不佳。 I've used the format painter as well as editing the rule to be applied over a range of cells (ie $B$2:$B$5) as shown below but it only bases the formatting on the initial formula (if B4 is greater than C4) and everything undesirably turns red.我使用了格式刷并编辑了应用于一系列单元格(即 $B$2:$B$5)的规则,如下所示,但它仅基于初始公式(如果 B4 大于C4) 并且所有东西都意外地变成红色。在此处输入图片说明

I'd rather not make individual rules for every row.我宁愿不为每一行制定单独的规则。 Is there a way to consolidate this into one rule?有没有办法将其合并为一个规则?

You need to take out the $ signs before the row numbers in the formula....and the row number used in the formula should correspond to the first row of data, so if you are applying this to the ("applies to") range $B$2:$B$5 it must be this formula您需要在公式中的行号之前取出 $ 符号......并且公式中使用的行号应对应于第一行数据,因此如果您将其应用于(“适用于”)范围 $B$2:$B$5 一定是这个公式

=$B2>$C2

by using that "relative" version rather than your "absolute" one Excel (implicitly) adjusts the formula for each row in the range, as if you were copying the formula down通过使用“相对”版本而不是“绝对”版本,Excel(隐式)调整范围内每一行的公式,就好像您正在向下复制公式一样

I don't know if maybe it's a difference in Excel version but this question is 6 years old and the accepted answer didn't help me so this is what I figured out:我不知道 Excel 版本是否有所不同,但这个问题已有 6 年历史了,接受的答案对我没有帮助,所以这就是我想出的:

Under Conditional Formatting > Manage Rules:在条件格式> 管理规则下:

  1. Make a new rule with "Use a formula to determine which cells to format"使用“使用公式确定要设置格式的单元格”制定新规则
  2. Make your rule, but put a dollar sign only in front of the letter: $A2<$B2制定规则,但仅在字母前放置美元符号: $A2<$B2
  3. Under "Applies to", Manually select the second column (It would not work for me if I changed the value in the box, it just kept snapping back to what was already there), so it looks like $B$2:$B$100 (assuming you have 100 rows)在“适用于”下,手动选择第二列(如果我更改框中的值,它对我不起作用,它只是不断恢复到已经存在的内容),所以它看起来像$B$2:$B$100 (假设您有 100 行)

This worked for me in Excel 2016.这在 Excel 2016 中对我有用。

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

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