View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 587
Default Throwing #Value in a UDF written in Excel VBA

hi Dom,

one possibility is to declare the arguments of type Optional

Sub test()
MyFonction Arg1:=0, Arg2:=56765765
MyFonction Arg1:=453
MyFonction Arg2:=56765765
MyFonction
End Sub


Function MyFonction(Optional Arg1 As Variant, Optional Arg2 As Variant)
As Variant
MsgBox "Arguments manquants:" & vbCrLf & _
IsMissing(Arg1) & " / " & IsMissing(Arg2)
End Function

each argument can be verified by type
TypeName
VarType
IsDate
IsNumeric
IsEmpty
IsMissing
IsArray
IsObject
IsNull

isabelle

Le 2013-02-21 14:11, Dom a écrit :
I just wrote a UDF in excel's VBA. If the arguments are wrong, I'd
like to have #Value appear in the cell. Is there a way to throw this
exception in a VBA function?