[英]How to remove formula from cell and replace with number in VBA?
Say I've got a cell, C1.假设我有一个单元格,C1。 The formula in C1 is =A1*B1, which equals 2. How do I remove the formula and replace it with just the resulting number after it's been calculated?
C1 中的公式是 =A1*B1,等于 2。如何删除公式并在计算后仅将其替换为结果数字? I've tried this:
我试过这个:
Dim x As Long
x = .Range("C1").Value
.Range("C1").Value = x
This does not work, because x attempts to store the formula, not the calculation of said formula.这不起作用,因为 x 试图存储公式,而不是计算所述公式。
If you want the result of the calculation just use如果您想要计算结果,只需使用
With .Range("C1")
.Value2 = .Value2
End With
If you want the formula use .Formula
如果你想要公式使用
.Formula
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.