ertucode
ertucode

Reputation: 655

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.

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

Upvotes: 2

Views: 190

Answers (1)

braX
braX

Reputation: 11755

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.

Upvotes: 2

Related Questions