繁体   English   中英

在VBA中的公式中使用字符串变量

[英]Using string variables within a formula in VBA

我不明白为什么这段代码行不通:

Cells(i, formula_col_index).Value = "=IF(" & time_location & "<>" & time_benchmark & ",""ERROR"",""OK"")"

哪里

time_location=" 17:00:00",
time_benchmark=" 17:30:00"

它不断抛出应用程序定义的(或对象定义的)错误。

提前致谢。

由于您的变量time_locationtime_benchmark包含字符串值,因此在使用公式时,应在双引号中包括它们:

Cells(i, formula_col_index).Value = "=IF(""" & time_location & """<>""" & time_benchmark & """,""ERROR"",""OK"")"

暂无
暂无

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

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