User Defined Functions

  • Thread starter Thread starter matthew.clegg
  • Start date Start date
M

matthew.clegg

I'm keen to learn how to write my own functions and would like to use
some microsoft functions as a starting point.
So using =ceiling(number,multiple/digit) as an example can anyone
supply the code that would be required to make this function if it
didn't exist already in excel?
Thanks
Matty
 
This is probably not a perfect implementation - but I hope it gives you some
ideas:

Public Function MyCeiling(dblInputVal As Double, dblCeiling As Double) As
Double

Dim dbltemp As Double
Dim lngtemp As Long
Dim dblOutVal As Double

lngtemp = Int((dblInputVal / dblCeiling))

dbltemp = (dblInputVal / dblCeiling)

If lngtemp <> dbltemp Or lngtemp = 0 Then
dblOutVal = dblCeiling * (lngtemp + 1)
Else
dblOutVal = dblCeiling * lngtemp
End If

MyCeiling = dblOutVal

End Function
 
Back
Top