View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Leave cell value untouched if Custom Function errors

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