Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XL2K3 UDF Error 1

Status
Not open for further replies.

MeGustaXL

Technical User
Aug 6, 2003
1,055
GB
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?

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!

 
Put it in a module rather than the sheet code, and try again.

Cheers, Glenn.

Beauty is in the eye of the beerholder.
 
Ha! Of course - I'm a chimp, and you Glenn are a STAR [2thumbsup]

Chris

Someday I'll know what I'm donig...damn!

 
I'm glad you got it working! :)

And thanks for the star!!!

Cheers, Glenn.

Beauty is in the eye of the beerholder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top