+ Reply to Thread
Results 1 to 5 of 5

Conditional Calculation

  1. #1
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Melbourne, VIC, Australia
    MS-Off Ver
    Office 365
    Posts
    243

    Conditional Calculation

    One of the sheets in my workbook contains a cross-reference grid that takes a considerable amount of grunt to recalculate.

    The problem is that whenever I change anything else it wants to recalculate this page every time, which takes about 20 seconds each time.

    I cannot just switch the Options to Manual Calculation because that affects the whole workbook. I do want it to calculate other sheets automatically.

    There are even parts of the sheet in question that I want it to recalculate (eg, grid labels).

    I presume I can tell it somehow in the Worksheet_Calculate event to ignore a particular range under certain conditions when recalculating, but what is the actual mechanism, ie how would I code it, to not calculate for a given region?

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    The manual/auto calculate option is an application level setting as you've pointed out, so it's either on or off. What you can do is "interupt" the calculation if the cell that's caused the recalc is within the range in question. I'd suggest you look at the Worksheet_Calculate event and put code in there to halt it if target.address is in your range (look at the Intersect function to determine if the target is in your range). Hope that helps. MM.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Melbourne, VIC, Australia
    MS-Off Ver
    Office 365
    Posts
    243
    *puts on construction worker's helmet*

    singing (after a fashion):
    Matrix, Matrix Man!
    I wanna be a Matrix Man!

    *removes construction worker's helmet and looks around with embarrassment hoping nobody was watching*


    Sorry, MM, I probably didn't put it clear enough because that didn't answer the question I was asking. To put it another way, I know I need to put code into Worksheet_Calculate but what specific function or coding approach would I use to prevent the calculation if a target cell falls into the range (a simple, single rectangular range) that is not to be calculated?

    In addition, I imagine Worksheet_Calculate is itself called with a range to be recalculated. Given that range parameter, how do I divide the cells that can be calculated from those which should not?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    In VBA, you can recalculate the workbook, a sheet, a range, or a single cell using the Calculate method., e.g.
    Please Login or Register  to view this content.
    See Help for the Calculate method.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Have you looked at setting Excel>Options>Calculation to Automatic Except Tables?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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