0

我得到一个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))"
4

2 回答 2

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 中插入变量...

于 2013-09-18T16:10:32.977 回答
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))"
于 2013-09-18T16:08:56.190 回答