Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Sunnous
 
Posts: n/a
Default Changing a Parameter Of A Formula

Hi,

I would be grateful if someone could help me with the problem have got.

I have written a macro, with my user defined functions. One of my user
defined functions is called GetData and it has two parameters Reference and
Last_Value, eg GetData(Reference, Last_Value).

I call GetData by assigning this to a cell like so (which works fine):

Cell.Formula = GetData(Reference, Last_Value)

Now within the GetData function I use the Reference Parameter to get a New
Value, which will be returned to the cell (which works fine too). But what I
wanted to know is how can I change the Last_Value Parameter to the new Value
I have, which also change Last_Value which is assigned to cell while I'm
still in the GetData function.

Thanks

Sunnous
  #2   Report Post  
Frank Kabel
 
Posts: n/a
Default

Hi
see your other post

"Sunnous" wrote:

Hi,

I would be grateful if someone could help me with the problem have got.

I have written a macro, with my user defined functions. One of my user
defined functions is called GetData and it has two parameters Reference and
Last_Value, eg GetData(Reference, Last_Value).

I call GetData by assigning this to a cell like so (which works fine):

Cell.Formula = GetData(Reference, Last_Value)

Now within the GetData function I use the Reference Parameter to get a New
Value, which will be returned to the cell (which works fine too). But what I
wanted to know is how can I change the Last_Value Parameter to the new Value
I have, which also change Last_Value which is assigned to cell while I'm
still in the GetData function.

Thanks

Sunnous

  #3   Report Post  
Myrna Larson
 
Posts: n/a
Default

I think what you are asking is, can the function return a calculated result to
the cell containing the formula and ALSO change that formula by modifying its
arguments.

The answer is NO. Functions can only calculate results. They can't change the
underlying cell content, which is the formula. A Sub procedure could do that,
but not a function called from a formula in a worksheet cell.

You can achieve something similar via circular references and iteration.

Let's say you write this function:

Function Test(N As Long)
Application.Volatile
Test = N + 1
End Function

and in C1 you put the formula =Test(C1).

This creates a circular reference, and the formula will work ONLY if you turn
on iterations and set the number of iterations to 1. After doing that, the
value in C1 will increment by 1 every time the worksheet is recalculated. But
no matter now many times you recalculate the worksheet, the *formula* remains
unchanged. It's still =Test(C1)

In general, if a procedure (sub or function) receives arguments passed ByRef,
the procedure can change any one of those arguments. If that procedure is used
ONLY within a VBA project, you will have no problems. But if it's called,
directly or indirectly, from a worksheet formula, it will return #VALUE!

On Thu, 28 Oct 2004 06:15:06 -0700, "Sunnous"
wrote:

Hi,

I would be grateful if someone could help me with the problem have got.

I have written a macro, with my user defined functions. One of my user
defined functions is called GetData and it has two parameters Reference and
Last_Value, eg GetData(Reference, Last_Value).

I call GetData by assigning this to a cell like so (which works fine):

Cell.Formula = GetData(Reference, Last_Value)

Now within the GetData function I use the Reference Parameter to get a New
Value, which will be returned to the cell (which works fine too). But what I
wanted to know is how can I change the Last_Value Parameter to the new Value
I have, which also change Last_Value which is assigned to cell while I'm
still in the GetData function.

Thanks

Sunnous


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
revert formula insertion to old method Don't be a pain in the ass Setting up and Configuration of Excel 0 January 24th 05 01:49 PM
Simple formula doesn't quite add up circeo Excel Discussion (Misc queries) 3 January 17th 05 09:04 PM
How do I keep a formula from changing if a row is added or deleted cwolt Excel Discussion (Misc queries) 1 December 27th 04 11:18 PM
How do I keep a formula from changing if a row is added or delete. cwolterman Excel Discussion (Misc queries) 1 December 27th 04 09:13 PM
Can I use TODAY Function in formula without it changing the next . Tucson Guy Excel Discussion (Misc queries) 1 December 19th 04 09:47 AM


All times are GMT +1. The time now is 04:29 PM.

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"