vassili
07-23-2007, 04:10 AM
i've been stuck on this for a good hour. i'm trying to figure out why the "num" function won't return "invalid" when i use the "IsError" function to try to catch a math error.
like if i try to evluate "1/0" or "string1/string2"
Sub getPrice()
'...some code
Range("A1").Formula = "1"
Range("B1").Formula = "1b"
Range("C1").Formula = "0"
Range("A3").Formula = "=Num(A1,B1,C1)"
End Sub
Function Num(qty As Range, uPrice As Range, pcs As Range)
Dim err As Boolean
err = IsError(Val(qty) * Val(uPrice) / Val(pcs))
If err Then
Num = "Invalid"
Else
Num = (Val(qty)) * Val(uPrice) / Val(pcs))
End If
End Function
like if i try to evluate "1/0" or "string1/string2"
Sub getPrice()
'...some code
Range("A1").Formula = "1"
Range("B1").Formula = "1b"
Range("C1").Formula = "0"
Range("A3").Formula = "=Num(A1,B1,C1)"
End Sub
Function Num(qty As Range, uPrice As Range, pcs As Range)
Dim err As Boolean
err = IsError(Val(qty) * Val(uPrice) / Val(pcs))
If err Then
Num = "Invalid"
Else
Num = (Val(qty)) * Val(uPrice) / Val(pcs))
End If
End Function