2015-03-03 37 views
0

我在Sheet 1中定义自己的宏,例如:如何将VBA宏添加到公式栏中的标准函数列表中?

Function MyPower(rad As Double) As Double 
Dim res As Double 
If rad = 0 Then 
    res = 0 
Else 
    res = 0.01 * Exp(1.7 * Log(rad)) 
Power = res 
End If 
End Function 

我希望能够通过公式栏调用它等的标准功能之一,即FX = MyPower(“A1”)例如,与fx = Cos(“A1”)相同。

我需要做什么才能将此宏添加到配方栏中?我相信这很简单,但默认情况下不起作用。

回答

1

简单!在一个Module中创建你的函数,而不是一个Sheet宏。

您还误放置和打错的返回值...

Function MyPower(rad As Double) As Double 
    Dim res As Double 
    If rad = 0 Then 
     res = 0 
    Else 
     res = 0.01 * Exp(1.7 * Log(rad)) 
    End If 
    MyPower = res ' <-- "MyPower": Move it here 
End Function 
+0

也只是要清楚,因为他可能认为它不可能有相同的名字 - ,返回变量必须具有相同的名称作为UDF(用户定义函数) – 2015-03-03 08:30:28

相关问题