在公式中组合变量和单元格地址

combine variable and cell address in a formula

我有以下代码:

Dim displacement As Double
    init_displacement = Range("C3").Value

Dim lastrow As Long

    lastrow = Range("A" & Rows.Count).End(xlUp).Row

    Range("E2:E" & lastrow).FormulaR1C1 = "=RC[-2] - [" & init_displacement & "]"

我在手册或网上找不到什么是与单元格地址结合时从公式中减去的正确表达式。有人要吗?

更新:

我最终使用了

poc_posuv = (CLng(-(Sheets(1).Range("C2").Value)))

然而,这采用 C2 值 22,651(注意小数点逗号)并将其四舍五入为 23。有人知道为什么 CLng 函数会这样做吗?似乎很愚蠢分配Long数据类型并且仍然将其四舍五入是不合理的...

我想你正在寻找:

"=RC[-2] - " & init_displacement

即没有方括号。

您缺少第二个 Cell 的 RC。 替换

"=RC[-2] - [" & init_displacement & "]"

"=RC[-2] - RC[" & init_displacement & "]"