Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default How to propagate xlErrNull back to Excel formula?

The VBA code below conceptionally does what I want, namely: propagate
an error raised in a "lower" subroutine back the Excel formula that
called the function. But it does not work as intended unless I remove
the "as String" declaration for the function (i.e. make the function
type Variant). Not surprisingly, the function fails with #VALUE, not
#NULL.

Is there some way to propagate the error back from a non-variant
function, whatever it might be?

Conceptual VBA code ....

Function testit(arg) As String ' invoked by =testit(x), where x is
0 or 1
On Error GoTo goterror
Call testit2(arg)
MsgBox "testit okay"
testit = arg
Exit Function

goterror:
MsgBox "testit error " & Err.Number
testit = CVErr(Err.Number)
End Function


Sub testit2(arg)
Call testit3(arg)
MsgBox "testit2"
End Sub


Sub testit3(arg)
If arg Then Err.Raise xlErrNull
MsgBox "testit3"
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 417
Default How to propagate xlErrNull back to Excel formula?

Function testit must be declared As Variant for it to be able to return
error values.

Function testit(arg) As Variant

In general, I usually end up declaring UDFs (User-Defined Functions) as
Variant anyway, just to allow for returning error values, if needed.

--
Regards,
Bill Renaud



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default How to propagate xlErrNull back to Excel formula?

On Dec 1, 8:25 pm, "Bill Renaud"
wrote:
Function testit must be declared As Variant for it to be able to return
error values.


I suspected that is the case. Thanks for the confirmation.
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
Propagate....copy Data Brandy Excel Discussion (Misc queries) 0 May 24th 10 06:28 PM
Auto propagate formulae? MikeR New Users to Excel 2 September 21st 08 11:16 PM
Can I propagate a date from one worksheet to another DJ Excel Worksheet Functions 1 April 27th 05 03:23 AM
Propagate Array Formula Down Column [email protected] Excel Discussion (Misc queries) 1 February 20th 05 07:42 AM
Propagate labels from Worksheet Ligaya Excel Programming 2 November 16th 04 02:36 PM


All times are GMT +1. The time now is 09:37 PM.

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

About Us

"It's about Microsoft Excel"