Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Restoring the current result of failing user-defined functions

Hello,

In my project I create user-defined functions in Excel. Some of them do I/O
operations that are not always available. In such case a user-defined
function returns #INVALID value to the result cell.

My question: If there is previously calculated value in the result cell, is
it possible to restore it in case my functions are not able to return a
value at a time? Is there some API or technique that can be used?

I understand that there could be certain complications - for example in case
the UDF is part of a formula.

Thank you for your time!

Nacho


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Restoring the current result of failing user-defined functions


I discover that I can use Application.Caller property to identify the UDF
caller cell, but when retrieving then I have circular reference error. Any
idea how I can avoid this problem?

Thank you,
Nacho


"Nacho Nachev" wrote in message
...
Hello,

In my project I create user-defined functions in Excel. Some of them do

I/O
operations that are not always available. In such case a user-defined
function returns #INVALID value to the result cell.

My question: If there is previously calculated value in the result cell,

is
it possible to restore it in case my functions are not able to return a
value at a time? Is there some API or technique that can be used?

I understand that there could be certain complications - for example in

case
the UDF is part of a formula.

Thank you for your time!

Nacho




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Restoring the current result of failing user-defined functions

You will have to checkmark the iteration checkbox in the calculate tab of
Tools=Options to allow circular references.

--
Regards,
Tom Ogilvy



"Nacho Nachev" wrote in message
...

I discover that I can use Application.Caller property to identify the UDF
caller cell, but when retrieving then I have circular reference error. Any
idea how I can avoid this problem?

Thank you,
Nacho


"Nacho Nachev" wrote in message
...
Hello,

In my project I create user-defined functions in Excel. Some of them do

I/O
operations that are not always available. In such case a user-defined
function returns #INVALID value to the result cell.

My question: If there is previously calculated value in the result cell,

is
it possible to restore it in case my functions are not able to return a
value at a time? Is there some API or technique that can be used?

I understand that there could be certain complications - for example in

case
the UDF is part of a formula.

Thank you for your time!

Nacho






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Restoring the current result of failing user-defined functions

This works excellent for me. Unfortunately, this won't work if the UDF if
part of formula expression. For instance:

= Max(MyFunc(A1), 10)

If I find the root Caller for the whole formula expression, this will work
fine for me. Does anybody have any suggestion?

Thank you,
Nacho


"Tom Ogilvy" wrote in message
...
You will have to checkmark the iteration checkbox in the calculate tab of
Tools=Options to allow circular references.

--
Regards,
Tom Ogilvy



"Nacho Nachev" wrote in message
...

I discover that I can use Application.Caller property to identify the

UDF
caller cell, but when retrieving then I have circular reference error.

Any
idea how I can avoid this problem?

Thank you,
Nacho


"Nacho Nachev" wrote in message
...
Hello,

In my project I create user-defined functions in Excel. Some of them

do
I/O
operations that are not always available. In such case a user-defined
function returns #INVALID value to the result cell.

My question: If there is previously calculated value in the result

cell,
is
it possible to restore it in case my functions are not able to return

a
value at a time? Is there some API or technique that can be used?

I understand that there could be certain complications - for example

in
case
the UDF is part of a formula.

Thank you for your time!

Nacho








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Restoring the current result of failing user-defined functions

Hi Nacho,

This works OK for me when I turn on iteration: what problem do you get?

You might want to consider an alternative technique to circular references:
- when your function exits cache the result somewhere (static or global
variable or use Range.ID)
- then if your I/O operation fails return the previous result from the cache

This would avoid the unfortunate side-effects of using circular references.


Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com

"Nacho Nachev" wrote in message
...
This works excellent for me. Unfortunately, this won't work if the UDF if
part of formula expression. For instance:

= Max(MyFunc(A1), 10)

If I find the root Caller for the whole formula expression, this will work
fine for me. Does anybody have any suggestion?

Thank you,
Nacho


"Tom Ogilvy" wrote in message
...
You will have to checkmark the iteration checkbox in the calculate tab

of
Tools=Options to allow circular references.

--
Regards,
Tom Ogilvy



"Nacho Nachev" wrote in message
...

I discover that I can use Application.Caller property to identify the

UDF
caller cell, but when retrieving then I have circular reference error.

Any
idea how I can avoid this problem?

Thank you,
Nacho


"Nacho Nachev" wrote in message
...
Hello,

In my project I create user-defined functions in Excel. Some of them

do
I/O
operations that are not always available. In such case a

user-defined
function returns #INVALID value to the result cell.

My question: If there is previously calculated value in the result

cell,
is
it possible to restore it in case my functions are not able to

return
a
value at a time? Is there some API or technique that can be used?

I understand that there could be certain complications - for example

in
case
the UDF is part of a formula.

Thank you for your time!

Nacho












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Restoring the current result of failing user-defined functions

Hi Charles,

This works OK for me when I turn on iteration: what problem do you get?


I am sorry. I have had an error in my test case. It seems that it works fine
for me too, when I turn on iteration.

You might want to consider an alternative technique to circular

references:
- when your function exits cache the result somewhere (static or global
variable or use Range.ID)
- then if your I/O operation fails return the previous result from the

cache

Your suggestion has been my original thinking about the problem. However, I
wanted to be sure that there is no other more trivial way that is inherent
to Excel design. Well, at this point I consider that the approach you
suggest is the most resonable. Still I'll elaborate a bit more on the Caller
approach to explore the side effects and see if the will hinder my macros.

Thank you!

This would avoid the unfortunate side-effects of using circular

references.


Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com

"Nacho Nachev" wrote in message
...
This works excellent for me. Unfortunately, this won't work if the UDF

if
part of formula expression. For instance:

= Max(MyFunc(A1), 10)

If I find the root Caller for the whole formula expression, this will

work
fine for me. Does anybody have any suggestion?

Thank you,
Nacho


"Tom Ogilvy" wrote in message
...
You will have to checkmark the iteration checkbox in the calculate tab

of
Tools=Options to allow circular references.

--
Regards,
Tom Ogilvy



"Nacho Nachev" wrote in message
...

I discover that I can use Application.Caller property to identify

the
UDF
caller cell, but when retrieving then I have circular reference

error.
Any
idea how I can avoid this problem?

Thank you,
Nacho


"Nacho Nachev" wrote in message
...
Hello,

In my project I create user-defined functions in Excel. Some of

them
do
I/O
operations that are not always available. In such case a

user-defined
function returns #INVALID value to the result cell.

My question: If there is previously calculated value in the result

cell,
is
it possible to restore it in case my functions are not able to

return
a
value at a time? Is there some API or technique that can be used?

I understand that there could be certain complications - for

example
in
case
the UDF is part of a formula.

Thank you for your time!

Nacho












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
User defined functions without using VBA. [email protected] Excel Worksheet Functions 0 June 13th 06 05:44 PM
User Defined Functions Mike McLellan Excel Worksheet Functions 2 May 4th 06 10:56 AM
current row of user-defined function? usenethelp Excel Programming 5 July 22nd 04 04:53 AM
excel functions and User defined functions Kanan Excel Programming 4 May 20th 04 11:21 PM
current cell in user-defined function Julio Kuplinsky Excel Programming 3 December 8th 03 06:24 PM


All times are GMT +1. The time now is 12:54 AM.

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"