Issue with UDF and when it will recalculate

TomCon

Active Member
Joined
Mar 31, 2011
Messages
385
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have discovered the following about a UDF and when it recalculates. Which i find quite confusing. Can anybody make sense of this, and better yet, how do i get it to work "as it should".<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
If i have a UDF with two range arguments,<o:p></o:p>
MyUdf(range1, range2)<o:p></o:p>
<o:p></o:p>
The UDF has Application.Volatile(False)<o:p></o:p>
<o:p></o:p>
When i put the following formula in a cell<o:p></o:p>
=MyUdf(A1,B1)<o:p></o:p>
it recalculates whenever A1, or B1 change, so that seems "correct".<o:p></o:p>
<o:p></o:p>
When i put the following formula in a cell<o:p></o:p>
=MyUdf((OFFSET(A1,C1,0),B1)<o:p></o:p>
It does NOT recalculate if cell C1 changes. Why not? If the OFFSET formula is naked in a cell, it will recalculate if C1 changes. Why is this "hidden" from the Excel recalc engine if it is an argument to MyUdf?<o:p></o:p>
<o:p></o:p>
And, even worse, i have discovered that, in the second case, now if cell B1 changes, myUdf still does not recalculate. This seems really confusing. Why does the OFFSET function in arg1, cause Excel to not recalculate MyUdf if cell B1 changes?<o:p></o:p>
<o:p></o:p>
I have confirmed all of the above by setting breakpoints. Both of the above seem "wrong" to me at least. It seems like it should be easy for Excel to recognize that MyUdf needs to be reevaluated in either case, above (and especially the second). Scary that you can have wrong answers before your eyes and not realize it.<o:p></o:p>
<o:p></o:p>
So, now, assuming my statements above are correct, how do i get MyUdf to recalcuate if EITHER of the data for its arguments change, that is, if either B1 or C1 change, in the formula above? I do not want to set Volatile to TRUE as i have many calls to the UDF.<o:p></o:p>

Thanks!<o:p></o:p>
Tom<o:p></o:p>
<o:p></o:p>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I'm not really sure but my first thought was that OFFSET() is a volatile formula, so any UDF that relies on it probably needs to be volatile also.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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