'Worksheets("Sheet1").Range("B2:B" & lastrow).Formula = "=IF(ISNA(VLOOKUP($A19,Sheet2!$A$2:$BA$26,MATCH("New Ratio number",Sheet2!$1:$1,0),FALSE)),VLOOKUP($A19,Sheet3!$A$1:$AH$465,MATCH("Coverage (Number)",Sheet3!$1:$1,0),FALSE),VLOOKUP($A19,Sheet2!$A$2:$BA$26,MATCH("New Ratio number",Sheet2!$1:$1,0),FALSE))"
覆盖率(数量)和新比率数字是列名称(我怀疑列名是一个问题) 当我在单元格中插入Vlookup时它正在工作,但它在VBA中显示语法错误。此外,我已经检查了其他公式,这意味着在lastrow或代码中的任何其他语句中没有问题。有人能指出问题吗?感谢
答案 0 :(得分:1)
在字符串周围加倍双引号。
Worksheets("Sheet1").Range("B2:B" & lastrow).Formula = "=IF(ISNA(VLOOKUP($A19,Sheet2!$A$2:" & _
"$BA$26,MATCH(""New Ratio number"",Sheet2!$1:$1,0),FALSE)),VLOOKUP($A19,Sheet3!$A$1:" & _
"$AH$465,MATCH(""Coverage (Number)"",Sheet3!$1:$1,0),FALSE),VLOOKUP($A19,Sheet2!$A$2:" & _
"$BA$26,MATCH(""New Ratio number"",Sheet2!$1:$1,0),FALSE))"
答案 1 :(得分:0)
你必须使用额外的双引号来逃避双引号:
Worksheets("Sheet1").Range("B2:B" & lastrow).Formula = "=IF(ISNA(VLOOKUP($A19,Sheet2!$A$2:$BA$26,MATCH(""New Ratio number"",Sheet2!$1:$1,0),FALSE)),VLOOKUP($A19,Sheet3!$A$1:$AH$465,MATCH(""Coverage (Number)"",Sheet3!$1:$1,0),FALSE),VLOOKUP($A19,Sheet2!$A$2:$BA$26,MATCH(""New Ratio number"",Sheet2!$1:$1,0),FALSE))"