vba Excel 2007 有 2 个条件的条件格式,一个基于另一列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10184339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel 2007 Conditional formatting with 2 conditions, one based off another column
提问by Patrick Bride
I'm using a table in Excel 2007. I'm trying to highlight cells in one column based off of its value and its status (which is in another column) in one format.
我正在使用 Excel 2007 中的表格。我试图根据其值及其状态(在另一列中)以一种格式突出显示一列中的单元格。
For example, I'm trying to highlight all cells (only the cells, not the row) with gross profits that are negative and have a status of "IN". What is the correct way to do this? I've tried if statements, but did not have much success. And I am not sure how to apply two conditions to the cells. Would I need to select the column or range of cells? Or would I have to select the first cell and copy the format?
例如,我试图突出显示毛利润为负且状态为“IN”的所有单元格(仅单元格,而不是行)。这样做的正确方法是什么?我试过 if 语句,但没有取得多大成功。而且我不确定如何将两个条件应用于单元格。我需要选择单元格的列或范围吗?还是我必须选择第一个单元格并复制格式?
Thanks,
谢谢,
Example:
例子:
Item # Status Gross Profit 1 IN .00 2 OUT $(34.00) 3 OUT .00 4 IN .00 5 IN $(9.00) 6 IN $(40.00) 7 OUT .00 8 OUT .00 9 OUT .00 10 IN .00 11 OUT $(18.00) 12 IN .00 13 IN $(25.00)
Average .00
回答by davesnitty
This works in Excel 2010:
这适用于 Excel 2010:
I'm assuming the cells you want to highlight are in column C...
我假设您要突出显示的单元格在 C 列中...
- highlight all cells in column C
- Click Conditional Formatting->Highlight Cells Rules->More Rules
- Choose "use a formula..."
- for the formula, enter : =AND(C2<0, $b2="IN")
- Click the "format" button and choose the highlight color of your choice
- Click OK
- 突出显示 C 列中的所有单元格
- 单击条件格式->突出显示单元格规则->更多规则
- 选择“使用公式...”
- 对于公式,输入:=AND(C2<0, $b2="IN")
- 单击“格式”按钮并选择您选择的突出显示颜色
- 单击确定
Although you've defined the formula in terms of the topmost cell, Excel will generalize to the whole column.
尽管您已根据最上面的单元格定义了公式,但 Excel 将推广到整列。