" & time_benchmark -6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:12:54 25 4
gpt4 key购买 nike

我不明白为什么这段代码不起作用:

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

关于vba - 在 VBA 的公式中使用字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22176248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com