Creating a custom function with VBA Excel, error #VALUE -


public function copperthermalconductivity(t double, rrr double)      dim p1, p2, p3, p4, p5, p6, p7 double     dim w0, w1, w10 double     dim beta, betar double      beta = 0.634 / rrr     betar = beta / 0.0003      p1 = 0.00000001754     p2 = 2.763     p3 = 1102     p4 = -0.165     p5 = 70     p6 = 1.756     p7 = 0.838 / (betar ^ 0.1661)      w0 = beta / t     w1 = (p1 * (t ^ p2)) / (1 + (p1 * p3 * (t ^ (p2 + p4)) * worksheetfunction.exp(-(p5 / t) ^ p6)) + w0)     w10 = (p7 * w1 * w0) / (w1 + w0)      copperthermalconductivity = (1 / (w0 + w1 + w10))  end function  sub describefunctioncopper()    dim funcname string    dim funcdesc string    dim argdesc(1 2) string     funcname = "copperthermalconductivity"    funcdesc = "returns thermal conductivity in w/m-k"     argdesc(1) = "temperature in kelvin"    argdesc(2) = "residual-resistivity ratio"     application.macrooptions _       macro:=funcname, _       description:=funcdesc, _       argumentdescriptions:=argdesc, _       category:="cryogenics" end sub 

i wrote code create accessible function excel. somehow when use function on excel #value error, idea? don't error when build macro. me please.

this line source of error:

w1 = (p1 * (t ^ p2)) / (1 + (p1 * p3 * (t ^ (p2 + p4)) * worksheetfunction.exp(-(p5 / t) ^ p6)) + w0) 

you cannot use worksheet function exp in vba code. there vba equivalent exp() , should used instead of worksheet function.


by way, note when declare variables that:

dim p1, p2, p3, p4, p5, p6, p7 double dim w0, w1, w10 double dim beta, betar double 

only p7, w10 , betar declared double, other declared variant. if want declare variables double should that:

dim p1 double, p2 double, p3 double, p4 double, p5 double, p6 double, p7 double dim w0 double, w1 double, w10 double dim beta double, betar double 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -