编译错误语句末尾带有" "



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

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

尝试:

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

最新更新