用“”编译语句的错误结尾

时间:2018-08-14 15:27:59

标签: vba excel-vba compiler-errors

我希望在单元格中显示以下内容,但在语句结尾出现编译错误。和/或在单元格中仅显示WA,而不显示“ WA”。我应该在此代码中添加什么?

ActiveCell = "=IF(Rater!D6 = "WA",'Unity Country rate'!F55,VLOOKUP(Rater!E12,'Country rate'!A18:B205,2,FALSE))"

1 个答案:

答案 0 :(得分:0)

尝试:

ActiveCell.Formula = "=IF(Rater!D6=""WA"",'Unity Country rate'!F55,VLOOKUP(Rater!E12,'Country rate'!A18:B205,2,FALSE))"

您需要在大引号内加上双引号。


为更好地解释这一点,请考虑将字符串链接在一起:

x = "cat"
y = " and "
z = "dog"
cell(1,1).value = x & y & z 'cat and dog

填写变量:

cell(1,1).value = "cat" & " and " & "dog"

看起来很有趣,但是您要添加项目,因此需要&符号以及实际的书面内容在引号内。如果字符串中包含内部引号,并且需要显示它们,则需要从本质上关闭并重新打开字符串,以便捕获这些其他引号:

cell(1,1).value = "cat and dog"
cell(1,1).value = "cat ""and"" dog" 'will add quotations within, such that cat "and" dog
相关问题