带有列表条件的EXCEL中嵌套的IF / AND语句

时间:2018-03-21 16:42:15

标签: excel if-statement excel-formula

我理解嵌套IF / AND语句,但当我的条件是列表{}时,我没有得到所需的结果。无论如何,如果没有创建一个"辅助单元"?

就可以解决这个问题
=IF(AND(C2="CBHNP",F2="CHAM"),"CBHNP-Franklin Fulton",IF(AND(C2="CBHNP",F2<>"CHAM"),"CBHNP-Capital Region",IF(AND(C2="CCBH",F2={"RPSY","RDG","CSBERKS"}),"CCBH-Berks",IF(AND(C2="CCBH",F2={"YORK","YORK-P","CSYORK"}),"CCBH-YORK",IF(AND(C2="CCBH",F2<>{"YORK","YORK-P","CSYORK","RPSY","RDG","CSBERKS"}),"CCBH-North Central",B2)))))

1 个答案:

答案 0 :(得分:2)

简要说明:AND(A1={1,2,3})始终为False,因为它与AND(A1=1,A1=2,A1=3)相同,而A1一次只能有1个值。

因此,遵循相同的原则,AND(C2="CCBH",F2={"RPSY","RDG","CSBERKS"})也始终为False,因为它与写AND(C2="CCBH",F2="RPSY",F2="RDG",F2="CSBERKS")相同,而F2只能有1个值。如果你使用ORAND(C2="CCBH",OR(F2={"RPSY","RDG","CSBERKS"})) 可以 True,就像OR(A1={1,2,3})一样。它也可以重写为OR(AND(C2="CCBH",F2="RPSY"), AND(C2="CCBH",F2="RDG"), AND(C2="CCBH",F2="CSBERKS"))

因此:

=IF(AND(C2="CBHNP",F2="CHAM"),"CBHNP-Franklin Fulton",IF(AND(C2="CBHNP",F2<>"CHAM"),"CBHNP-Capital Region",IF(AND(C2="CCBH",OR(F2={"RPSY","RDG","CSBERKS"})),"CCBH-Berks",IF(AND(C2="CCBH",OR(F2={"YORK","YORK-P","CSYORK"})),"CCBH-YORK",IF(AND(C2="CCBH",F2<>{"YORK","YORK-P","CSYORK","RPSY","RDG","CSBERKS"}),"CCBH-North Central",B2)))))