Excel函数表给出错误

我在Excel(Mac)中用户定义函数的第一次尝试并不顺利。 这给“function或子未定义”:

Function CylArea(d0 As Double, theta As Double, y As Double) As Double CylArea = Pi() * (d0 ^ 2 / 4 + d0 * Tan(Radians(theta)) * y + Tan(Radians(theta)) ^ 2 * y ^ 2) End Function Function CylVolume(d0 As Double, theta As Double, y As Double) As Double CylVolume = Pi() * (d0 ^ 2 / 4 * y + 1 / 2 * d0 * Tan(Radians(theta)) * y ^ 2 + 1 / 3 * Tan(Radians(theta)) ^ 2 * y ^ 3) End Function Function CylAreaDeriv(d0 As Double, theta As Double, y As Double) As Double CylAreaDeriv = Pi() * (d0 * Tan(Radians(theta)) + 2 * Tan(Radians(theta)) ^ 2 * y) End Function 

奇怪的是, CylVolumePi被突出显示。

它看起来像你试图使用Excel函数,就像在VBA代码中的工作表中一样。 这可能无法正常工作。

尝试将Pi()所有实例更改为WorksheetFunction.Pi ,将所有TanMath.Tan实例以及Radians所有实例更改为WorksheetFunction.Radians ,以使代码看起来更像这样:

 Function CylVolume(d0 As Double, theta As Double, y As Double) As Double CylVolume = WorksheetFunction.Pi * (d0 ^ 2 / 4 * y + 1 / 2 * d0 * Math.Tan(WorksheetFunction.Radians(theta)) * y ^ 2 + 1 / 3 * Math.Tan(WorksheetFunction.Radians(theta)) ^ 2 * y ^ 3) End Function