IF(AND 多条件语句

IF(AND statement with multiple criterias

我正在尝试编写一个包含多个条件的公式,但似乎不太正确。

公式按原样工作,但我需要包括 "SHOT10"、"SHOT20"、"SH15" 和 "SH20"

=IF(AND(C5194="SHOT15",H5194="",I5194=""),E5194,"")

有人可以帮我修改上面的公式吗?

=IF(
    AND(
        OR( C5194="SHOT10", C5194="SHOT15", C5194="SHOT20", C5194="SH15", C5194="SH20" ),
        H5194="",
        I5194=""
       ),
    E5194,
    ""
   )

AND(C5194="SHOT15",H5194="",I5194="")相当于说:

C5194="SHOT15" And H5194="" And 15194=""

所以您在 VBA 代码中的内容是:

If C5194="SHOT15" And H5194="" And 15194="" Then
    ActiveCell = E5194
Else
    ActiveCell = ""
End

您可以使用 AND( 和 OR( 来指定不同的参数。

例如,如果我想在 'A1' 中提取 3 个不同的值,但要确保 'B1' 和 'C1' 为空,我可以使用:

=IF(AND(OR(A1="A",A1="B",A1="C"),B1="",C1=""),"True","False")

所以在你的具体情况下:

The issue now is that I now need to also consider SHOT10, SHOT20, SH15 and SH20 as well. Meaning that if either SHOT15, SHOT10, SHOT20, SH15 or SH20 appears in C5194 and H5194 is blank and I5194 is also blank then return the value of E5194 else return blank. The key is that all the conditions must be met for the value of E5194 be returned

您的公式变为:

=IF(AND(OR(C5194="SHOT15",C5194="SHOT10",C5194="SHOT20",C5194="SH15",C5194="SH20"),H5194="",I5194=""),E5194,"")

编辑: 根据 barry houdini:

使用数组常量缩短
=IF(AND(OR(C5194={"SHOT15","SHOT10","SHOT20","SH15","SH20"}),H5194="",I5194=""),E5194,"")