PDA

View Full Version : erase #value!



ratvoleur
02-03-2009, 07:20 PM
Hi,

I have this code

function number( n as double) as double

number=n+1

end function


Simple

Now I want; if someone decide to put a string instead a double in the cell to show something like msgbox("error") and erase #value!

Please help me!

Thx :)

Sagy
02-03-2009, 07:48 PM
Hi,

I have this code

function number( n as double) as double

number=n+1

end function


Simple

Now I want; if someone decide to put a string instead a double in the cell to show something like msgbox("error") and erase #value!

Please help me!

Thx :)

One easy way (not sure it is the best) is to do the following:

Function number(n As Variant) As Variant

If IsNumeric(n) Then
number = n + 1
Else
Call MsgBox("Error", vbCritical )
number = ""
End If

End Function