带引号的公式中的预期语句结尾 [英] Expected End of Statement in formula with quotes

查看:74
本文介绍了带引号的公式中的预期语句结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sub FillNames()

Range("D2:D56").SpecialCells(xlCellTypeBlanks).Formula = _
    "=IF(AND(C>800,C<900),  "YES", "NO")"

End Sub

我得到预期的编译错误:语句结束. YES和NO前后的引号似乎有问题.

I get the compile error expected: end of statement. It seems to have issue with the quotes around the words YES and NO.

如果我删除是"和否"周围的引号并运行宏,它将运行并将公式引号中的内容打印到单元格中.我不明白那引号是怎么引起语法错误的.

If I remove the quotes around YES and NO and run the macro, it will run and print what is in the formula quotes into the cell. I don't understand then how the quotes cause a syntax error.

我正在运行Mac的Excel 2011,不知道这是否与它有关.

I am running Excel 2011 for Mac, don't know if that has anything to do with it.

推荐答案

字符串中的双引号需要通过加倍来进行转义:

Double-quotes in strings need to be escaped by doubling them up:

Range("D2:D56").SpecialCells(xlCellTypeBlanks).Formula = _
                    "=IF(AND(C>800,C<900),  ""YES"", ""NO"")"

这篇关于带引号的公式中的预期语句结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆