View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Trouble updating a cell's text that has a formula in it through VB

You seem to have a misunderstanding.
The formula produces the text - even the error values.

Just to illustrate:
if you wanted your udf to produce an error value you would use

Public MyFunct(r as Range)
if r is nothing then
Myfunct = cvErr(xlErrRef)
exit function

' other code
end Function
as an example

or just to show from the immediate window:

activecell.Value = cvErr(xlErrRef)
? activecell.Text
#REF!

So a cell can either contain a formula or a constant value. If you assign a
constant, it overwrites the formula. Sounds like you need to modify your UDF
to produce the information you need or put textboxes over your cells that
contain the text you want to see.

--
Regards,
Tom Ogilvy


"J. Caplan" wrote:

I have a multiple cells in an Excel Spreadsheet that all call a user defined
function. There is a case where a different action (calling VBA code in
Excel) that gets data back and needs to update the text of those cells that
have the formula.

I have the data that need in the array and I know the cells that need their
text updated. I can not use Range.Text since that is readonly. If I call
Range.Value = values(i) that updates the text of the cell, but it also wipes
out the formula. Is there a way to programmatically update the text of a
cell without wiping out the formula? When a formula produces an error, it
puts text in the cell without wiping out the formula, so it must be possible.