Expected End of Statement

微笑、不失礼 提交于 2020-01-21 18:16:15

问题


Ok, I have used a formula that was suggested that works well, should work without an issue but now I am getting this error:

Expected End of Statement

Here is the formula

 Range("B4").FormulaR1C1 = "=IF(RC[-1]="T",VLOOKUP(RC[7],treatlookup,11,FALSE),VLOOKUP(RC[7],itemlookup,22,FALSE))"

Not sure what is going on, why it is happening. Any suggestions.

Thanks,


回答1:


Escape the embedded double-quotes ("T") by doubling them (""T""):

Range("B4").FormulaR1C1 = "=IF(RC[-1]=""T"",VLOOKUP(RC[7],treatlookup,11,FALSE),VLOOKUP(RC[7],itemlookup,22,FALSE))"
                                      ^^^
                                       |
                                      Here

Excel is trying to pair the opening quote at "=IF with the next double-quote it finds, which is at "T", and that portion ("=IF(RC[-1]=") isn't a valid statement. Doubling them tells Excel to consider them separately, allowing them to be embedded in the formula correctly.

(The error is highlighted for you when you get the message, if you look at the code it's indicating; that's how I spotted it.)



来源:https://stackoverflow.com/questions/21768996/expected-end-of-statement

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