Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Throwing #Value in a UDF written in Excel VBA

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Throwing #Value in a UDF written in Excel VBA

Il giorno giovedì 21 febbraio 2013 20:11:38 UTC+1, Dom ha scritto:

Hi,
try

Public Function m(a)
'...
m = CVErr(xlErrValue)
End Function

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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Throwing #Value in a UDF written in Excel VBA

On Feb 21, 2:41*pm, isabelle wrote:
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?- Hide quoted text -


- Show quoted text -


Thanks, Maurizio, Exactly what I wanted.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Throwing #Value in a UDF written in Excel VBA

Il giorno giovedì 21 febbraio 2013 20:47:26 UTC+1, Dom ha scritto:

YW!

Thanks, Maurizio, Exactly what I wanted.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula throwing up an error Gotroots Excel Programming 4 November 26th 09 05:16 PM
Formula throwing up an error ker_01 Excel Programming 0 November 25th 09 11:06 PM
EXCEL VBA - Find Method or Range in IE throwing error Malik Excel Programming 3 March 30th 08 05:39 PM
Excel Throwing Circular Errors When No Errors Exist MDW Excel Worksheet Functions 1 August 10th 06 02:15 PM
Throwing Out top & lower percentages Gary Gonzales Excel Worksheet Functions 2 February 23rd 06 08:30 PM


All times are GMT +1. The time now is 11:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"