VBA - How to get the result of a formula ? (.Value always returns 0)

霸气de小男生 提交于 2020-01-06 04:04:23

问题


I want to get the result of a formula contained in a cell, but I always get 0 returned, instead of the real results.

I have the following:

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

And even if I try with Evaluate:

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

回答1:


Zero is the correct answer if both V22 and W22 are zero.




回答2:


Maybe try this:

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


来源:https://stackoverflow.com/questions/28832054/vba-how-to-get-the-result-of-a-formula-value-always-returns-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!