Public Function IfError(ByVal strExpr As String, ParamArray p() As Variant) As Variant
' strExpression in the form of:
' $1 * $2 / $3
'
' we then replace each $X with the supplied parameter
'
Dim i As Integer, e As String
On Error Resume Next
For i = 0 To UBound(p)
Select Case VarType(p(i))
Case vbDate
e = "#" & Format(p(i), "mm\/dd\/yyyy") & "#"
Case vbInteger, vbSingle, vbDouble, vbLong, vbByte, vbCurrency
e = p(i)
Case vbString
e = "'" & Replace(p(i), "'", "''") & "'"
Case vbNull
e = "Null"
End Select
strExpr = Replace(strExpr, "$" & i + 1, e)
Next
IfError = Eval(strExpr)
If Err.Number <> 0 Then
IfError = Null
End If
Err.Clear
End Function