Home > Net >  Using excel built-in functions with a variable
Using excel built-in functions with a variable

Time:05-16

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

CodePudding user response:

Here's a better way:

Public Function SIND(number As Double) As Double
  Dim Rads As Double
  Rads = WorksheetFunction.Radians(number)
  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.

  • Related