Make a custom UDF intentionally not to refresh

DGMan

New Member
Joined
Oct 19, 2017
Messages
7
I have a question that might be rather strange to you.

I have made a custom function which accept an input from a cell, and return a result by referencing some data source which will be updated periodically:

Code:
FUNCTION GiveSthOut(Input as Variant) As Variant

<do something="" by="" referencing="" a="" constantly-changing="" data="" source="" outside="" excel="">'Code which will reference a data source constantly being updated

GiveSthOut = Something

END FUNCTION

Normally, if the external source is changed and I choose to manually recalculate the UDF, the function result will be updated.

Now for some reason I wish to lock (or freeze) the function display result from being refreshed even though the external source has been changed. Initially I have come up with something like that:

Code:
FUNCTION GiveSthOut(Input as Variant, Optional Locked as Variant) As Variant

If Locked then 

   'Code that reference a data source which will be updated constantly<do something="" by="" referencing="" a="" constantly-changing="" data="" source="" outside="" excel="">

  GiveSthOut = Something

End If

END FUNCTION

My thinking is that, if the optional "Locked" argument is set to TRUE, then the bulk of the function would be by-passed so the present result of the function would be preserved or frozen. Unfortunately, the function result will not be frozen, for the value 0 will be return to the function in this case, which is definitely what I wanted. So is there any way, via programming code, to prevent a function result from being updated. Thanks for your advice in advance.

Fred.</do></do>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
The only way I can think that you might explore is to paste the result of the formula as a value the first time the UDF runs - maybe by a worksheet change event code

But as you don't specify when you would want to do this it is hard to be more specific

For your example why haven't you got
Code:
If NOT Locked then 

   'Code that reference a data source which will be updated constantly<do excel="" outside="" source="" data="" constantly-changing="" a="" referencing="" by="" something="">

  GiveSthOut = Something

End If
</do>

Rather than what you posted?
 
Upvote 0

Forum statistics

Threads
1,217,308
Messages
6,135,754
Members
449,963
Latest member
palm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top