+ Reply to Thread
Results 1 to 15 of 15

triggering a non volatile UDF()

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    triggering a non volatile UDF()

    I'm not positive that I completely understand volatility yet.

    I have 2 Dynamic Named Ranges (Code & Desc), which are obviously volatile. But the values in the Ranges are 99.9% static, so I'm trying to figure out how to keep formulas that refer to the Ranges non volatile.
    But for that 0.1% of the time that the value changes I need the formulas to recalculate.
    I think I have figured it out, but I'd like to see if anyone sees a problem with my solution or if there is a better solution somewhere.

    Please Login or Register  to view this content.
    The idea here is that when I select a code in cell $F$1, $G$1 obviously recalculates, just what I want.
    But when I change cell $B$3 to "bcb" (about once a year), I need $G$1 to recalculate.

    The only problem I can see with this is:
    I sometimes work with EnableEvents turned off. If I change $B$3 while it's off, it won't update when I turn Events back on.

    So I'm still working to find a way around that. Any suggestions?
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: triggering a non volatile UDF()

    Will this help ?
    Please Login or Register  to view this content.
    Kind regards, Harry.

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: triggering a non volatile UDF()

    I don't want myUDF to be volatile. 99.9% of the time. I just want it to recalculate if one of the values in the Dynamic Range changes.

  4. #4
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: triggering a non volatile UDF()

    I've tried to imitate.
    Attached Files Attached Files
    Last edited by HSV; 05-20-2012 at 03:39 PM.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,881

    Re: triggering a non volatile UDF()

    I can't download HSV's file, so he may have already suggested this. The key I've found to getting a UDF to fit into the calculation dependency tree that Excel builds (and that it uses to determine when a function needs to be recalculated) is to put all the necessary values that it takes from the spreadsheet and pass them to the function through the argument list. Right now, your UDF is accessing the Code and Desc ranges as hard coded references inside the function, and Excel cannot see these dependencies. So change it to something like:
    Please Login or Register  to view this content.
    called as =myudf($F$1,myrecalc,code,desc)\

    I did that quick, so double check my syntax and spelling, and make sure it still works right. The basic idea is to get all the dependencies passed to the function through the argument list.

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: triggering a non volatile UDF()

    I think that's what I've done.
    Code is stable. myRecalc is changed in the Worksheet_Change() whenever something in Desc is changed, which then forces myUDF() to recalculate.

    I was hoping someone could look at my solution and confirm that there is nothing that could change that myUDF() did not pick up.

    I also can't download HSV's file at this time.

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,881

    Re: triggering a non volatile UDF()

    Is that the whole purpose of the change event procedure (to make it act like code and desc are in the argument list without actually putting them into the argument list)? If the procedures only reason for existing is to control when G1 recalculates, it seems like a lot more work than just passing those arguments through the argument list and letting Excel's built in dependency tree determine when G1 needs to recalculate.

    I do notice that your change event doesn't actually change myrecalc. The other possible thing to look at is that myrecalc is trying to be changed when events are disabled. Perhaps this is preventing the calculation event from firing when myrecalc is changed.

  8. #8
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: triggering a non volatile UDF()

    A Dynamic Range is recalculated with every calculation in any open workbook, so Code and Desc are constantly being recalculated. My Worksheet_SelectionChange() stores the row & column numbers (for conditional formatting) so Code and Desc are being recalculated whenever I move the cursor in any open workbook. But they are static 99.9% of the time, which needlessly slows down all workbooks when this one is open.
    By putting both Code and Desc inside the UDF, Excel doesn't keep recalculating the Range Names, which speeds up all my workbooks.

    But I have to handle the 0.1% of the time when a value inside Desc changes. By having the Worksheet_Change() check to see if a value inside Desc has been edited and changing myReCalc when it does, it causes myUDF() to be recalculated only when a value inside Desc has changed (or when the size of the ranges change) which is what I've been trying to accomplish for over a year. It's not as easy as just letting Excel figure every thing out, but it speeds up my workbooks.

    You're right that Worksheet_Change doesn't actually change myReCalc, but it does force Excel into marking the cell for recalculation. Excel doesn't keep track of whether the value has actually changed, only that the cell was edited.
    Disabling events when changing myReCalc just prevents Worksheet_Change from being triggered again. This wouldn't do any harm in this situation, but the rest of the Worksheet_Change() might do harm.
    If it doesn't disable events then the order of things would be:
    1) Edit Desc which triggers 1st round of Worksheet_Change.
    2) Worksheet_Change determines that Desc has been edited and changes myReCalc which triggers 2nd round of Worksheet_Change().
    3) 2nd round of Worksheet_Change doesn't care that myReCalc has been edited so continues to end.
    4) 1st round of Worksheet_Change finishes.

  9. #9
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: triggering a non volatile UDF()

    My English is not so good as well.
    Your hole story is a bit to long for me to get de clou.
    Maybe this will help.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: triggering a non volatile UDF()

    HSV;
    I don't want to mark the entire sheet Dirty. Then every formula that refers to anywhere on the sheet would be recalculated. That would probably be worse than what I already have.

  11. #11
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: triggering a non volatile UDF()

    Maybe?
    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: triggering a non volatile UDF()

    That's the same thing as Range("G1").Value = Range("G1").Value
    I keep forgetting about "Dirty" because I've never used it. I'll use it now, so maybe next time I'll remember it.

  13. #13
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,881

    Re: triggering a non volatile UDF()

    Having never used dynamic named ranges, I didn't realize that that was the real cause of the issue. Unfortunately that also means that I probably can't be of any help on this one.

  14. #14
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: triggering a non volatile UDF()

    Hi,
    What happens if you do an
    Application.Calculate or Application.CalculateFull ?

    Will this recalculate all those UDFs?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  15. #15
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: triggering a non volatile UDF()

    They do no calculate, because none of the precedents for the UDFs are Dirty. I do think they calculate once when the file is opened, so the file takes a long time to open, but then it runs faster after that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1