嵌套的IF / AND语句

时间:2017-07-31 15:48:36

标签: excel if-statement excel-formula

我认为我已经犯了一个错误,因为它一直在返回#VALUE

IF(AND(G2="green",G3="green"),"GG"), IF(AND(G2="red",G3="red"),"RR"),
IF(AND(G2="red",G3="green"),"RG"), IF(AND(G2="green",G3="red"),"GR")

我试图说它是红色还是绿色,打印RG和其他如RR,GR,GG。

2 个答案:

答案 0 :(得分:2)

IF()函数有三个参数:TestThen-valueOtherwise-value。所以函数应该是这样的:

=IF(AND(G2="green",G3="green"),
    "GG",IF(AND(G2="red",G3="red"),
            "RR",IF(AND(G2="red",G3="green"),
                    "RG",IF(AND(G2="green",G3="red"),
                            "GR"))))

答案 1 :(得分:1)

试一试,

=IF(SUM(COUNTIF(G2:G3,{"red","green"}))=2,UPPER(LEFT(G2)&LEFT(G3)), TEXT(,))