[英]Using excel built-in functions with a variable
I am an excel noob trying to make a custom excel function that uses degrees while calculating sin of an angle.我是一个 excel 菜鸟,试图制作一个自定义 excel 函数,该函数在计算角度的 sin 时使用度数。
Public Function SIND(number As Double)
Formula = "SIN(RADIANS(number))"
Formula = Replace(Formula, "number", number)
SIND = Evaluate(Formula)
End Function
So far I have this but it doesn't work到目前为止,我有这个,但它不起作用
Here's a better way:这是一个更好的方法:
Public Function SIND(degrees As Double) As Double
Dim Rads As Double
Rads = WorksheetFunction.Radians(degrees)
SIND = Sin(Rads)
End Function
The main problem with your way is that you were mixing string functions to do math calculations, and that's just not the best method.您的方式的主要问题是您正在混合字符串函数来进行数学计算,这不是最好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.