View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
EricG EricG is offline
external usenet poster
 
Posts: 220
Default Another UDF Question

Nick,

Thanks for the response. Here are some more specifics:

1. The UDF takes the data in the referenced range and draws a dial gage
from it. The gage has from one to three scales, each scale having its own
needle pointing to the current value. The gage is the object I refer to.
The final value of the UDF is not relevant in any way. I use the UDF to draw
and update the gage.

2. In an earlier question, I tried to understand why my gage would not
update (redraw) when I had the RAND() function in one of the cells in that
gage's range. The RAND() function changed the value of the cell, but the UDF
did not trigger. I discovered that if I included the value of that cell in
the UDF's result, the gage would update. I could also add
Application.Volatile to the UDF, but that forces every UDF on the sheet to do
a complete update every time anything changes. However...

3. If one of the values in the gage's range changes, I don't always want to
redraw the entire gage - way too slow, so I'm okay with the fact that
updating one cell in the range will not necessarily force the gage to redraw.
Instead, I want to determine if the value of one of the gage's needles
changed (a specific cell in the range referred to by the UDF), and then only
adjust the needle's rotation. The gage is composed of a group of drawing
objects with a consistent naming convention that helps me refer to individual
components.

The trick is that when the Worksheet_Change event occurs (or
Worksheet_Calculate?), I want to see which cell or cells changed, figure out
which UDF is referencing those cells, determine which part of the gage is
impacted, and only update that part.

BTW,

If you include all cells that influence the result of your UDF in the
argument list (and then, of course, in the list of arguments of the function
call in the worksheet), then everything should work OK.


The above is not entirely true when the cells contain volatile formulas,
unless the change in those cells changes the value (result) of the UDF. At
least it seems to work that way.

Thanks for your help,

Eric


"Niek Otten" wrote:

Hi Eric,

If you don't mind, your post is a bit "vague" in some places;

<do some other stuff What stuff
<changes to cells that affect my UDF affect HOW?
<object the UDF is controlling ?????

If you include all cells that influence the result of your UDF in the
argument list (and then, of course, in the list of arguments of the function
call in the worksheet), then everything should work OK.
No need to trap events.
Note that functions can return a value to replace their call, nothing else.
They can not change cells, formats, really nothing at all. That is, as long
as they are called from worksheets, directly or indirectly.

If that doesn't answer your question, please post back and explain what you
are trying to achieve.


--
Kind regards,

Niek Otten
Microsoft MVP - Excel