2015-03-03 75 views
1

我想获得单元格中包含的公式的结果,但我总是得到0返回,而不是实际结果。VBA - 如何获得公式的结果? (.Value总是返回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 
+1

我测试此代码,它为我工作得很好。 – 2015-03-03 12:49:05

回答

1

零是正确的答案,如果这两个V22W22为零。

+0

不,他们没有,我的Excel在整个列中显示了其他结果:1.1,0.6,0.9,....但是在VBA(.Value)中,它们都返回0。 – Leon 2015-03-03 13:37:48

+0

是计算模式手动还是自动? – 2015-03-03 13:46:05

+0

确保没有多余的空间会导致公式无效。 – 2015-03-03 13:48:23

0

也许试试这个:

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 
+0

我看不到有任何变化,但我尝试过,它确实返回了与以前相同的结果:0始终为0 – Leon 2015-03-03 13:56:26

+0

也许你的行或列ID是错的?它是单元格(rowIndex,columnID)。你也可以这样写:c = ... cells(“E5”) – 2015-03-03 14:04:19

+0

只是顺便说一句,你的公式不应该是= ASIN((W22-V22)/ $ D $ 7)* 180/PI()? – 2015-03-03 14:10:36