+ Reply to Thread
Results 1 to 7 of 7

Only manually calculate user defined function

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010, Excel 2011 for mac
    Posts
    82

    Only manually calculate user defined function

    Hi Excel forum!

    I have a User Defined Function that takes alot of computational power. For most day-to-day changes to the worksheet it is not necessary to refresh the calculations called by the UDF.

    Is it possible to modify the UDF function, so it only executes when needed? i.e. when the user presses 'Calculate now' (F9)?

    regards,
    KBKA

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Only manually calculate user defined function

    Place this code in the code module for ThisWorkbook. Do the following: Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the left hand pane, double click on "ThisWorkbook". Copy/paste the macro into the empty window that opens up. Close the window to return to your sheet. Save the file, close it and then re-open it. Each time you open the file, the first macro will set calculation to manual so that calculations are not refreshed. When you want to refresh the calculations, click 'Calculate now'. When you close the file, the second macro will set calculation back to automatic.
    Please Login or Register  to view this content.
    The one problem is that while this file remains open, all calculations are also not refreshed in any other workbooks that may be open until the file is closed.
    Last edited by Mumps1; 06-29-2020 at 09:12 AM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

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

    Re: Only manually calculate user defined function

    Are you only considering some kind of "hot key" arrangement? I would probably pass an additional boolean argument to the function and use that to toggle between calculate this function and don't calculate this function. Something like:
    Please Login or Register  to view this content.
    Pass TRUE or any non-zero number to the function and it returns "waiting..." and skips over the rest of the function code. Pass FALSE or 0, and it will perform the rest of the calculations.
    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
    06-28-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010, Excel 2011 for mac
    Posts
    82

    Re: Only manually calculate user defined function

    Hi Mumps1,

    Thanks. But this doesn't solve my problem, as it would leave the entire workbook set to manual calculation. That's not what I'm after.

  5. #5
    Registered User
    Join Date
    06-28-2011
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010, Excel 2011 for mac
    Posts
    82

    Re: Only manually calculate user defined function

    Hi MrShorty,

    Something like that could work if the outputs from the previous calculation were still shown. With your suggestion the cells output is "Waiting...", which messes up the remaining formulas in the worksheet.
    So is it possible to store the current cell values and show give this as funciton output.

    Any ideas?
    Last edited by AliGW; 06-30-2020 at 03:58 AM. Reason: Please don't quote unnecessarily!

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,922

    Re: Only manually calculate user defined function

    What if you replace "Waiting.." with
    Please Login or Register  to view this content.

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

    Re: Only manually calculate user defined function

    ByteMarks solution can work, but, in my tests in my version of Excel, Excel generated a "circular reference" warning. I expect that solutions like ByteMarks will require you to enable iteration in Excel settings. Are you allowed to change that setting?

    If I were doing it, rather than use Application.Caller to get the current value, I would prefer to pass the value as another argument to the UDF
    Please Login or Register  to view this content.
    . If the UDF is called from B1, then the function call looks like =MYUDF(arguments...,TRUE,B1).

+ 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. [SOLVED] getting user defined type not defined when trying to add a reference manually
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2019, 10:48 AM
  2. user-fdefined type not defined after calculate
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2015, 11:36 AM
  3. Complex User-Defined Function to calculate CFs and discount them
    By arthuro in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2014, 08:23 AM
  4. [SOLVED] User-defined function to calculate quartiles
    By ATLGator in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-18-2014, 11:43 AM
  5. Excel 2007 : User defined search and calculate
    By PunterHunter in forum Excel General
    Replies: 4
    Last Post: 10-20-2011, 09:20 AM
  6. User defined function to calculate difference
    By antonymiller in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2010, 03:41 PM
  7. [SOLVED] calculate now for user defined functions?
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2006, 03:10 AM

Tags for this Thread

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