[英]#VALUE Error in Evaluate Function of Excel VBA
I am trying to find out what is wrong with the process below.我试图找出下面的过程有什么问题。 In my sheet, there is a formula string which needs evaluation for different values of variable, x .
在我的工作表中,有一个公式字符串需要对变量x 的不同值进行评估。
(0.5*(23-9.81)*3*(x^2))*(x/3)+(0.5*9.81*(x^2))*(x/3)-1*((0.5*18.5*0.33*(2.5^2))*(x+2.5/3)+(18.5*0.33*2.5*x)*(x/2)+(0.5*(23-9.81)*0.33*(x^2))*(x/3)+(0.5*9.81*(x^2))*(x/3)+(100*0.33*(2.5+x))*((2.5+x)/2))
I have a vba code which looks like this:我有一个看起来像这样的 vba 代码:
Public Function ev(r As Range, x As Double) As Variant
ev = Application.Evaluate(Replace(r.Value, "x", x))
End Function
What's weird is that this function only works if the cell input is like奇怪的是,此功能仅在单元格输入类似于
=ev(Q25,10.01)
=ev(Q25,10.01)
but not但不是
=ev(Q25,10.000000001)
=ev(Q25,10.000000001)
or even甚至
=ev(Q25,10.00001)
=ev(Q25,10.00001)
Why is this happening?为什么会这样? I need the program to calculate using small increments of up to
0.0000000001
.我需要该程序使用高达
0.0000000001
小增量进行计算。 Thank you for your insights.谢谢你的见解。
There is a 255 character limit to a String
passed to Application.Evaluate
.传递给
Application.Evaluate
的String
有 255 个字符的限制。 You're running into that hard limit after Replace
ing x
with the corresponding numeric value.在
Replace
ing x
Replace
为相应的数值后,您遇到了硬限制。
Your options include:您的选择包括:
Evaluate
ing it in several steps.Evaluate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.