尝试使用IF(AND与三个条件的公式错误

时间:2019-07-01 21:21:04

标签: excel-formula

我正在尝试编写一个公式来评估三个单元格中的所有可能值,并在另一个单元格中对其进行评分。 Excel说我的公式有问题,但是我找不到它。感谢您的帮助。

我在整个电子表格中都使用IF(AND,但只有两个值。Excel接受这些公式。

=IF(AND(B2="No",B3="Red",B5="No"),0,
 IF(AND(B2="No",B3="Green",B5="No",2,
 IF(AND(B2="No",B3="Blue",B5="No",3,
 IF(AND(B2="No",B3="Yellow",B5="No",5,5,
 IF(AND(B2="No",B3="Red",B5="Yes"),0,
 IF(AND(B2="No",B3="Green",B5="Yes"),2,
 IF(AND(B2="No",B3="Blue",B5="Yes",3,
 IF(AND(B2="No",B3="Yellow",B5="Yes",5,
 IF(AND(B2="Yes",B3="Red",B5="Yes",0,
 IF(AND(B2="Yes",B3="Green",B5="Yes",1,
 IF(AND(B2="Yes",B3="Blue",B5="Yes",2,
 IF(AND(B2="Yes",B3="Yellow",B5="Yes",5,
 IF(AND(B2="Yes",B3="Red",B5="No",0,
 IF(AND(B2="Yes",B3="Green",B5="No",1,
 IF(AND(B2="Yes",B3="Blue",B5="No",2,
 IF(AND(B2="Yes",B3="Yellow",B5="No",3))))))))))))))))

Excel指出“此公式有问题”。

3 个答案:

答案 0 :(得分:2)

您有一个5,5,应该有一个5,并且在其中缺少许多)才能关闭AND s

=IF(AND(B2="No",B3="Red",B5="No"),0,
 IF(AND(B2="No",B3="Green",B5="No"),2,
 IF(AND(B2="No",B3="Blue",B5="No"),3,
 IF(AND(B2="No",B3="Yellow",B5="No"),5,
 IF(AND(B2="No",B3="Red",B5="Yes"),0,
 IF(AND(B2="No",B3="Green",B5="Yes"),2,
 IF(AND(B2="No",B3="Blue",B5="Yes"),3,
 IF(AND(B2="No",B3="Yellow",B5="Yes"),5,
 IF(AND(B2="Yes",B3="Red",B5="Yes"),0,
 IF(AND(B2="Yes",B3="Green",B5="Yes"),1,
 IF(AND(B2="Yes",B3="Blue",B5="Yes"),2,
 IF(AND(B2="Yes",B3="Yellow",B5="Yes"),5,
 IF(AND(B2="Yes",B3="Red",B5="No"),0,
 IF(AND(B2="Yes",B3="Green",B5="No"),1,
 IF(AND(B2="Yes",B3="Blue",B5="No"),2,
 IF(AND(B2="Yes",B3="Yellow",B5="No"),3,""))))))))))))))))

但是我认为您可以使用更简单的公式来做到这一点:

=IFERROR(IF(B2 = "No",CHOOSE(MATCH(B3,{"Red","Green","Blue","Yellow"},0),0,2,3,5),IF(B5="Yes",CHOOSE(MATCH(B3,{"Red","Green","Blue","Yellow"},0),0,1,2,5),CHOOSE(MATCH(B3,{"Red","Green","Blue","Yellow"},0),0,1,2,3))),"")

答案 1 :(得分:0)

您可以将逻辑以字符串形式放在一个单元格中(例如F1):

0NOREDNO 2NOGREENNO 3NOBLUENO 5NOYELLOWNO 0NOREDYES 2NOGREENYES 3NOBLUEYES 5NOYELLOWYES 0YESREDYES 1YESGREENYES 2YESBLUEYES 5YESYELLOWYES 0YESREDNO 1YESGREENNO 2YESBLUENO 3YESYELLOWNO

然后您的代码简化为:

=MID(F1, FIND(UPPER(B2&B3&B5),F1)-1, 1)

这也将使将来添加更多条件变得极为容易。

答案 2 :(得分:0)

尝试一下:

=IF(B3="Red",0,
 IF(B3="Green",
   IF(B2="Yes",1,
   IF(B2="No",2,NA())),
 IF(B3="Blue",
   IF(B2="Yes",2,
   IF(B2="No",3,NA())),
 IF(B3="Yellow",
   IF(AND(B2="Yes",B5="No"),3,5),
 NA()))))

希望有帮助