如果列表的所有值都出现在不同的列中,则更改 excel 中单元格的颜色?
Change color of cell in excel if all values of a list are present in different column?
如果列表的所有值都出现在不同的列中,我正在尝试更改 excel 中单元格的颜色。
我,还有另一列有一些值。
如果 MyList 的所有值,我希望 myColumn 单元格的颜色应该是 red不存在。
如果 MyList 中的所有值都出现在 myColumn 中,它应该是 green
我尝试使用 conditional formatting
来实现,但它会根据单个单元格的值更改单元格的颜色。
=INDEX(B2:H2,MATCH(D2,B13:B15,0))
如何根据列表的值进行操作?
查看图片:
myrow
的值是 VLOOKUP()
反对 mycolumn
,如果 isnumber()
将 return 为真,否则为假。然后对所有结果值执行 and()
,该结果可用于确定单元格的颜色。
所以通过将单元格的默认填充颜色设置为红色,它将默认为红色,除非满足以下格式规则,否则它将为绿色:
假设您有以下命名范围:
- MyList 在我的示例中是 Cell
B2:H2
;
- myColumn 在我的示例中是 Cell
B5:B7
。请注意,我以 Table 的形式命名了此范围,因此当我向此列添加值时,新值会自动添加到命名范围。 将 header myColumn
的背景颜色设置为红色。
然后可以将下面的公式设置为B4
单元格的条件格式规则,即header myColumn
:
=SUMPRODUCT(ISNUMBER(MATCH(MyList,myColumn,0))*1)=COLUMNS(MyList)
MATCH will compare the values in MyList
with myColumn
and return a number for a match and #N/A
for no match, ISNUMBER will convert the results to TRUE
or FALSE
. SUMPRODUCT will sum the results and if all values are matched it should return 7
in the above example. Then compare the summed result with the expected result COLUMNS(MyList)
which is 7
as well. If match, the formula will return TRUE
, which will then trigger the conditional format to turn the cell background colour to green.
如果我向 myColumn
添加更多值以匹配 MyList
:
Please note the formula only checks if all MyList
values are present in myColumn
but not the other way around, which means if your myColumn
also contains other number such as 8
, 9
, 10
which are not in MyList
, the header will still turn green as long as it contains all values from MyList
regardless if it has extra values or not.
如果您有任何问题,请告诉我。干杯:)
如果列表的所有值都出现在不同的列中,我正在尝试更改 excel 中单元格的颜色。
我,还有另一列有一些值。
如果 MyList 的所有值,我希望 myColumn 单元格的颜色应该是 red不存在。
如果 MyList 中的所有值都出现在 myColumn 中,它应该是 green
我尝试使用 conditional formatting
来实现,但它会根据单个单元格的值更改单元格的颜色。
=INDEX(B2:H2,MATCH(D2,B13:B15,0))
如何根据列表的值进行操作?
查看图片:
myrow
的值是 VLOOKUP()
反对 mycolumn
,如果 isnumber()
将 return 为真,否则为假。然后对所有结果值执行 and()
,该结果可用于确定单元格的颜色。
所以通过将单元格的默认填充颜色设置为红色,它将默认为红色,除非满足以下格式规则,否则它将为绿色:
假设您有以下命名范围:
- MyList 在我的示例中是 Cell
B2:H2
; - myColumn 在我的示例中是 Cell
B5:B7
。请注意,我以 Table 的形式命名了此范围,因此当我向此列添加值时,新值会自动添加到命名范围。 将 headermyColumn
的背景颜色设置为红色。
然后可以将下面的公式设置为B4
单元格的条件格式规则,即header myColumn
:
=SUMPRODUCT(ISNUMBER(MATCH(MyList,myColumn,0))*1)=COLUMNS(MyList)
MATCH will compare the values in
MyList
withmyColumn
and return a number for a match and#N/A
for no match, ISNUMBER will convert the results toTRUE
orFALSE
. SUMPRODUCT will sum the results and if all values are matched it should return7
in the above example. Then compare the summed result with the expected resultCOLUMNS(MyList)
which is7
as well. If match, the formula will returnTRUE
, which will then trigger the conditional format to turn the cell background colour to green.
如果我向 myColumn
添加更多值以匹配 MyList
:
Please note the formula only checks if all
MyList
values are present inmyColumn
but not the other way around, which means if yourmyColumn
also contains other number such as8
,9
,10
which are not inMyList
, the header will still turn green as long as it contains all values fromMyList
regardless if it has extra values or not.
如果您有任何问题,请告诉我。干杯:)