簡體   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