+ Reply to Thread
Results 1 to 6 of 6

VBA-function: How to avoid recalculations with every change in a worksheet

  1. #1
    Registered User
    Join Date
    12-29-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    VBA-function: How to avoid recalculations with every change in a worksheet

    Hello,

    I'm working with a VBA Function, which shuffels around some function-internal Arrays and calculates a value (XIRR).
    Even without having any Application.Volatile in the file this VBA Function is run even if I Input some text in an unused cell.
    I have hundreds of calls of the function in my worksheet so recalculation Needs some time I want to avoid.

    Is there anything I can do so that the function only runs when the values the function is based on are changed?

    Any idea?

    Best regards,
    Frank

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: VBA-function: How to avoid recalculations with every change in a worksheet

    Non VBA solution could be:

    Formula => Countoptions => Manual

    After all the changes you could use

    Formula => Countoptions => Automatic
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: VBA-function: How to avoid recalculations with every change in a worksheet

    You will probably have to post the code and spreadsheet so we can see and test what you are doing. I would guess that there is something in the argument list or one of the values being passed to the function that Excel is seeing change with every calculation event (any chance you are passing a volatile function like =NOW() or =TODAY() to this UDF)?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    12-29-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA-function: How to avoid recalculations with every change in a worksheet

    Hello,

    I uploaded a sample sheet with the function. All cal of the function are marked yellow. As I only have about 10 lines with values, the Problem is a bit difficult to see. Maybe you put a breakpoint and then Change something in an empty cell (put in [A6] for example...). Recalculation starts immediately.

    Many thanks in advance,

    Frank
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: VBA-function: How to avoid recalculations with every change in a worksheet

    The INDIRECT() function is a volatile function (http://www.decisionmodels.com/calcsecretsi.htm ). The references for each of your UDF calls are built using the INDIRECT() function. Because these INDIRECT() functions are volatile, they are calculated with each calculation event. Subsequently, each incidence of the UDF is also recalculated with each calculation event.

    In order to get these to be non-volatile, you will need a different strategy for identifying these ranges that does not use a volatile INDIRECT() or OFFSET() function. It is not clear to me exactly what the logic is behind creating these ranges, but perhaps a mixed absolute/relative reference. something like a$11:a13 (note that row 11 is fixed, but row 13 will adjust as the formula is copied).

  6. #6
    Registered User
    Join Date
    12-29-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: VBA-function: How to avoid recalculations with every change in a worksheet

    I did not know, that the INDIRECT() function is volatile. Thank you for this.

    The Problem I have is that I need the xirr function with "dynamic" ranges. As there can be some Switches of Shares the begin and end of the ranges depend on the date of the Switch. I will think about this and open a separate threat if needed.

    Many thanks for your help!
    Last edited by ulfd; 08-17-2014 at 06:19 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Stop Recalculations
    By faedother in forum Excel General
    Replies: 1
    Last Post: 06-05-2011, 07:56 PM
  2. Recalculations while sorting
    By gonzo5000 in forum Excel General
    Replies: 2
    Last Post: 09-05-2007, 11:27 AM
  3. Unwanted recalculations
    By Mosaic in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2007, 11:17 AM
  4. Speed up pivot table VBA code, avoid multiple recalculations
    By Ronny in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-16-2005, 04:00 PM
  5. Pivot Table recalculations
    By C0ppert0p in forum Excel General
    Replies: 1
    Last Post: 09-19-2005, 08:05 PM

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