简体   繁体   English

Excel错误:预期语句结尾,这是什么意思?

[英]Excel error: expected end of statement, what does this mean?

I am trying to write this formula into a cell via my script: 我试图通过我的脚本将此公式写入单元格:

  strFormulas(1) = "=IF(AND(I2<12.2,I2>=8.2),"t","f")"

And it keeps coming up as an error, even though it works just fine in the actual sheet if I manually input it into the cell. 即使我手动将其输入到单元格中,即使在实际的工作表中也可以正常工作,它仍会继续出现错误。 What is it expecting me to do here? 希望我在这里做什么?

You need to escape quotes. 您需要转义报价。 Try this: 尝试这个:

strFormulas(1) = "=IF(AND(I2<12.2,I2>=8.2),""t"",""f"")"

The issue that you are running into is that " is interpreted as beginning or ending a VBA string. So VBA parses your expression as 您遇到的问题是"被解释为VBA字符串的开头或结尾。因此VBA将表达式解析为

strFormulas(1) = "=IF(AND(I2<12.2,I2>=8.2),"

with "garbage" at the end. 以“垃圾”结尾。 This "garbage" is what it is complaining about. 这种“垃圾”是它所抱怨的。 If you need to include a " within a VBA string, use "" . 如果需要在VBA字符串中包含" ,请使用""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM