Re: Returning text from Userdefined Functions

Tech-Archive recommends: Fix windows errors by optimizing your registry



VBA won't allow me to use the statement goto End, which doesn't surprise me.
If I change goto End to goto EndIt and change End: to EndIt: then the
function seems to work fine. James

"Mike H" <MikeH@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:26BE01D5-F140-436E-A823-C1C3D5548CCD@xxxxxxxxxxxxxxxx
Hi

Because the error handler is called from the UDF it is subject to the same
limitations as the UDF so if there's an error in the called routine you
aren't notified and simply get the VALUE error in the cell. Check out the
error handler it sounds very much like the error is within that.

Mike

"DagL" wrote:

This is the cell where the function is called from. Sometimes the string
is
returned correct, but when the code has been in an error handler, the
cell
displays "#VALUE!"


"Mike H" wrote:

A UDF cannot change any cell other than the one it is called from.


"DagL" wrote:

Hello!

I have a user defined function to write data back to a database in my
Excel
***. I return a smal text to show the user if the function was
successful
or not. When I set the return value of the function in regular code,
it works
fine. But, when something goes wrong, the execution goes to an error
handler,
the function does not return the string I set anymore.

I have the code:


Public Function WriteData()
on error goto ErrorHandler

.
.
calculations
.
.

WriteData = "OK" 'This is returned correct
to the
cell

goto End

ErrorHandler:

WriteData = "Not OK" 'This returns #VALUE to the
cell

End:

End Function


Can someone tell me the reason of this behavior, and/or what I am
doing wrong?

Regards DagL


.


Quantcast