问题描述
我正在尝试为 Excel 创建一个公式,通过该公式,单元格将根据前一个单元格中的文本更改颜色.
I am trying to create a formula for Excel whereby a cell would change colour based on the text in the previous cell.
例如,如果单元格 B2 包含字母 X,然后 B3 是 Y,我希望 B3 变为绿色.
同样,如果 B2 包含 X 并且 B3 包含 W 我希望 B3 变成红色.
So for example if cell B2 contains the letter X and then B3 is Y, I would like B3 to turn green.
Equally, if B2 contains X and B3 contains W I would like B3 to turn red.
任何想法都非常感谢!
推荐答案
- 选择单元格 B3 并单击功能区中的条件格式按钮并选择新建规则".
- 选择使用公式确定要设置格式的单元格"
- 输入公式:
=IF(B2="X",IF(B3="Y", TRUE, FALSE),FALSE)
,为真时选择填绿色莉> - 创建另一条规则并输入公式
=IF(B2="X",IF(B3="W", TRUE, FALSE),FALSE)
并在为真时选择填充红色.
- Select cell B3 and click the Conditional Formatting button in the ribbon and choose "New Rule".
- Select "Use a formula to determine which cells to format"
- Enter the formula:
=IF(B2="X",IF(B3="Y", TRUE, FALSE),FALSE)
, and choose to fill green when this is true - Create another rule and enter the formula
=IF(B2="X",IF(B3="W", TRUE, FALSE),FALSE)
and choose to fill red when this is true.
更多详细信息 - 带有公式的条件格式会在公式计算结果为 TRUE 时应用该格式.您可以使用复合 IF
公式根据任何单元格的值返回 true 或 false.
More details - conditional formatting with a formula applies the format when the formula evaluates to TRUE. You can use a compound IF
formula to return true or false based on the values of any cells.
这篇关于Excel - 编程单元格以根据另一个单元格更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!