VBA - 如何获取一个公式的结果? (.value的总是返回0)(VBA - How to

2019-10-22 04:08发布

我想包含在一个单元格中公式的结果,但我总是返回0,而不是真正的结果。

我有以下几点:

Set c = .Cells (5,5)

MsgBox (c.Formula) ' this return the following: = ASIN (W22-V22/$D$7)*180/PI() 
MsgBox (c.Value) ' this returns 0
MsgBox (c.Value2) ' this returns 0 as well

即使我尝试评估:

evaluation = Application.Evaluate (c.Formula) 
MsgBox (c.Value) ' it still returns 0

Answer 1:

零是正确的答案,如果V22W22都为零。



Answer 2:

也许试试这个:

Sub formVal()

Dim c As Range

Set c = ThisWorkbook.Sheets(1).Cells(5, 5)

MsgBox (c.Formula) 
MsgBox (c.Value)
MsgBox (c.Value2)



End Sub


文章来源: VBA - How to get the result of a formula ? (.Value always returns 0)