【问题标题】:VBA, how to make formulas visible in ExcelVBA,如何使公式在 Excel 中可见
【发布时间】:2013-03-21 03:42:42
【问题描述】:
Dim n As Double
n = Sh.Range("B10").Value

Dim rate As Double
rate = (datefin - datedepart) / n

Cells(13, n + 3) = datefin

For y = n - 1 To x Step -1
Cells(13, y + 3) = datefin - rate
datefin = datefin - rate
Next y

我有一个简单的for 循环,它将值从n(由用户提供)开始并根据rate(也由用户)。

我得到的输出值是正确的,但我想让我的公式在 excel 中可见。例如,如果我按下单元格D13,我希望它显示我使用的公式。我尝试使用 ActiveCell.FormulaActiveCell.FormulaR1C1 函数来执行此操作,但由于 n 并不总是一个特定的数字(因此在特定的单元格上)我找不到如何执行我想要的。

谢谢!!!

【问题讨论】:

    标签: excel vba range formula cells


    【解决方案1】:

    一般而言,您会使用.Formula 将公式附加到单元格,但是如果各个组件实际上并未包含在电子表格的其他单元格中,那么您将能够做的最好的事情是

    Cells(13, y + 3).Formula = "=" & format(datefin) & " - " & format(rate)
    

    如果 datefin 为 9 且 rate 为 2,则将公式 "=9 - 2" 放入单元格中。

    【讨论】:

      猜你喜欢
      • 2017-04-24
      • 2018-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多