Excel IF / AND / OR语句

时间:2018-12-06 23:11:01

标签: excel-formula spreadsheet

感谢帮助:

我正在尝试编写两个IF / AND / OR语句以满足以下要求 我有五列,

1)如果所有列均为正数或某些列为正数且某些包含“ NA”,则我需要返回“正数”。

2)如果所有列均为负数或某些列为负数且其中一些包含“ NA”,那么我需要返回“负数”。

我第一个识别数字1的表达式正在按预期工作:

=IF(OR(AND(B2>=0, C2>=0,D2>=0,E2>=0,F2>=0,G2>=0,H2>=0), AND(B2="NA", C2="NA",D2="NA",E2="NA",F2="NA",G2="NA",H2="NA")), "POSITIVE", "ignore")

但是,相同的表达式只是从> = 0更改为<0,不能按我期望的那样工作,并且仅对所有列中都包含负数的行(即NA和负数的组合)仅返回“ NEGATIVE”数字未提取)。

=IF(OR(AND(B2<0, C2<0,D2<0,E2<0,F2<0,G2<0,H2<0), AND(B2="NA", C2="NA",D2="NA",E2="NA",F2="NA",G2="NA",H2="NA")), "NEGATIVE", "ignore")

1 个答案:

答案 0 :(得分:1)

使用

=IF(AND(SUM(B2:H2) = SUMIF(B2:H2,">=0",B2:H2),COLUMNS(B2:H2) = COUNT(B2:H2) + COUNTIF(B2:H2,"NA")),"Positive",IF(AND(SUM(B2:H2) = SUMIF(B2:H2,"<0",B2:H2),COLUMNS(B2:H2) = COUNT(B2:H2) + COUNTIF(B2:H2,"NA"),COUNTIFS(B2:H2,0)=0),"Negative","Ignore"))

enter image description here