Expected End of Statement in formula with quotes

我们两清 提交于 2019-12-31 03:01:17

问题


Sub FillNames()

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

End Sub

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.

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


回答1:


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"")"


来源:https://stackoverflow.com/questions/24173238/expected-end-of-statement-in-formula-with-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!