I cannot get Excel to calculate my VBA function; I keep getting a #NUM
error. I think it may be that I have a wrong type somewhere, but I
don't know how strongly typed Excel is.
My code, as it appears in Module1, is:
Option Explicit
Public Function PUp(Wt As Double, FTL As Integer, _
PoI As Integer, stdev As Double) As Double
Dim erfVal As Double
PUp = 0
'If Wt > FTL Then
' PUp = 0
'Else
' erfVal = (Wt - PoI) / stdev * [atpvbaen.xls].sqrt(2)
' If erfVal < 0 Then
' PUp = 1 - 0.5 * (1 + [atpvbaen.xls].ERF(erfVal))
' Else
' PUp = 0.5 * (1 + [atpvbaen.xls].ERF(erfVal))
' End If
'End If
End Function
For reference: the ERF function is the CDF for a normal distribution,
with a mean of PoI; it comes with the Analysis ToolPak add-in.
The Formula Bar reads:
=PUp($D2, FTL, PoI, 500*SQRT(2))
where
$D2 = 22,100.00
FTL = 42000
PoI = 38500
Most of the code is commented out because I wanted to see if it was
something in the If loops that was screwing up my function;
apparently, it wasn't. Any help would be greatly appreciated.