如何用 VBA 为 Excel 创建 Cosd 函数?

How to make a Cosd Function with VBA for Excel?

我需要创建一个以度为单位求余弦的函数。我在 Mac-OS Excel 2011

Function cosd(d)
    deg = (d * 3.14159265358979) / 180    
    cosd = WorksheetFunction.Cos(deg)
End Function

还是不行。

你真的很接近你的函数的唯一问题(嗯,除了不声明你的变量是不好的做法)是 Cos 不是 VBA 函数。将您的功能更改为

Function cosd(d As Double) As Double
  cosd = Application.WorksheetFunction.Cos((d * Application.WorksheetFunction.Pi) / 180#)
End Function

它应该工作得很好。