Hi there,
I've got this User Defined Function in a Sheet's VB code.
When I call it up in a cell, I get a #NAME? error.
What's up? How can I fix it?
Chris
Someday I'll know what I'm donig...damn!
I've got this User Defined Function in a Sheet's VB code.
When I call it up in a cell, I get a #NAME? error.
What's up? How can I fix it?
Code:
Function CBSPOIS(ByVal probability As Double, ByVal mean As Double)
2
On Error GoTo 16
Dim n As Long, v As Double, cumv As Double
If probability > 0.999999 Then probability = 0.999999
n = mean - 5 * (mean ^ 0.5) - 1
If n > 100 Then
v = Exp(n - mean - n * Application.Ln(n / mean)) / (Application.Pi() * (2 * n + 1 / 3)) ^ 0.5
cumv = v * mean / (mean - n)
Else
n = 0
v = Exp(-mean)
cumv = v
End If
If v = 0 Then GoTo 16
Do While probability > cumv
n = n + 1
v = v * mean / n
cumv = cumv + v
Loop
CBSPOIS = n
Exit Function
16 CBSPOIS = CVErr(xlErrNum)
End Function
Chris
Someday I'll know what I'm donig...damn!