vba vlookup /错误处理 - 类型不匹配错误

时间:2013-09-18 15:25:18

标签: vba error-handling vlookup

即时获得run time error 13 - type mismatch error

任何想法?

outputCell = "=IF(ISNA(VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE))," - ", (=VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE))"

2 个答案:

答案 0 :(得分:0)

在第二个(=之前摆脱VLOOKUP

您还没有在IsNA函数中正确转义双引号。

在一行上,尝试:

outputCell = "=IF(ISNA(VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE)),"" - "", VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE))"

为了易读,请将它分成多行:

outputCell = "=IF(ISNA(VLOOKUP(A" _
                  & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE))," _
                  & """ - "", VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" _
                  & 1000 & ",2,FALSE))"

答案 1 :(得分:0)

在VBA中的字符串中,你需要通过加倍来引用双引号。 因此,如果您想要一个包含Hello "bob" how are you?的字符串,您可以编写"Hello ""bob"" how are you?"

在您的代码中:

"=IF(ISNA(VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE))," - ", (=VLOOKUP(A" & row & ",'Current Defects'!$A$" & 2 & ":$B$" & 1000 & ",2,FALSE))"

由于," - ",部分,它变得混乱。您正试图减去字符串,这是无法完成的。

此外,你的公式没有意义。我建议先在Excel单元格中测试它,然后仔细修改它,在VBA中插入变量......