Excel:嵌套的IF和INDEX MATCH返回#N / A

时间:2016-09-14 09:24:00

标签: excel vba excel-vba

我有一张4张工作簿。我试图在第一张表中创建一个函数,用于检查下一张表中列中的值。如果在那里找不到该值,它将在下一个工作表中查找类似的列,依此类推。我有以下功能,它在查看工作表Dummy1和Dummy2时有效,但在查看Dummy3时返回#N / A.任何想法为什么会这样?

=IF(INDEX(Dummy1!$A$3:$A$1048576,MATCH(B1,Dummy1!$B$3:$B$2473,0))<>0,
INDEX(Dummy1!$A$3:$A$1048576,MATCH(B1,Dummy1!$B$3:$B$2473,0)),
IF(INDEX(Dummy2!$A$3:$A$1048576,MATCH(B1,Dummy2!$B$3:$B$2473,0))<>0,
INDEX(Dummy2!$A$3:$A$1048576,MATCH(B1,Dummy2!$B$3:$B$2473,0)),
INDEX(Dummy3!$A$3:$A$1048576,MATCH(B1,Dummy3!$B$3:$B$2473,0))))

2 个答案:

答案 0 :(得分:0)

如果匹配公式找不到匹配项,例如在Dummy1中,它将返回#N / A.反过来,这将中止if函数,而不是返回false并继续查看Dummy2。

尝试将逻辑测试包装在iferror函数中,该函数在出错时返回false。 But be mindful of using it too generously

=IF(IFERROR(INDEX(Dummy1!$A$3:$A$1048576,MATCH(B1,Dummy1!$B$3:$B$2473,0))<>0,FALSE),
INDEX(Dummy1!$A$3:$A$1048576,MATCH(B1,Dummy1!$B$3:$B$2473,0)),
IF(IFERROR(INDEX(Dummy2!$A$3:$A$1048576,MATCH(B1,Dummy2!$B$3:$B$2473,0))<>0,FALSE),
INDEX(Dummy2!$A$3:$A$1048576,MATCH(B1,Dummy2!$B$3:$B$2473,0)),
INDEX(Dummy3!$A$3:$A$1048576,MATCH(B1,Dummy3!$B$3:$B$2473,0))))  

答案 1 :(得分:0)

您的公式中没有任何错误处理 - 这样做:

=IF(TRIM($B$2)="","Please enter value into B2",IFERROR(IF(INDEX(Dummy1!$A:$A,MATCH($B$2,Dummy1!$B:$B,0),1)<>0,INDEX(Dummy1!$A:$A,MATCH($B$2,Dummy1!$B:$B,0),1),IF(INDEX(Dummy2!$A:$A,MATCH($B$2,Dummy2!$B:$B,0),1)<>0,INDEX(Dummy2!$A:$A,MATCH($B$2,Dummy2!$B:$B,0),1),IF(INDEX(Dummy3!$A:$A,MATCH($B$2,Dummy3!$B:$B,0),1)<>0,INDEX(Dummy3!$A:$A,MATCH($B$2,Dummy3!$B:$B,0),1),"Not in any of the sheets"))),"Not in any of the sheets"))