View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Stephen Brook Stephen Brook is offline
external usenet poster
 
Posts: 1
Default Leave cell value untouched if Custom Function errors

Tom,

Many apologies - I hadn't read your post correctly before my first reply. I
did indeed try your suggestion with the IF(ISERROR( etc. trap, which works
perfectly....

....but do you know of any way that you can perform the same trick inside the
custom function itself? I only ask because the file containing the custom
function is to be used by an end user who may find the conditional statement
confusing. It would be more elegant if I could perform the same error
trapping within the function itself.

I assume the problem is that by the time the custom function has been
triggered by a recalculate, the previous value in the cell is already lost -
unless you use iterations, as in your example?

Thanks again,

SB

"Tom Ogilvy" wrote:

Assume the function will be used in Cell A1. Go to Tools=Options,
Calculate tab and check the iteration checkbox (this will suppress the
circular reference warning). Set Max iterations to 1.

in A1 put in the formula:
=if(iserror(function),A1,Function)

In your function put in error handling so your function returns an excell
error (CVErr(xlErrValue) as an example) if there is a problem with the
connection.

--
Regards,
Tom Ogilvy

"StephenBrook" wrote in message
...
I have a custom function that uses arguments from the user's worksheet to
find data in an external Access database using ADO, then return it to the
relevant cell. It works fine, but I want to be able to ensure that the

custom
function leaves the cell value *untouched* (rather than returning an error
value) if the VBA cannot make the connection to the Access database (e.g.

if
the user can't access the database for some reason).

I've tried using Application.Caller to get the cell's original value, but
this doesn't seem to work. Can anyone help?

Thanks,

SB