I am working on an Excel Add-in and have created some custom functions in it. Now my user has created some functions (150+ custom functions) and all of these custom functions have parameters as references to other cells in sheet. When user updates some text cell (whether referred in some function call or not) , whole sheet is refreshed and Excel shows busy in all cells having custom functions it. I understand that if a cell is referred in some custom function and it is updated, that custom function is called to show updated data, but it should not happen when user edits a cell not referred in any of the functions.
I cannot change sheet calculation mode to manual as it will stop updating other cells which are changed by user. Also If I change calculation mode to Manual and on changing it back to Auto again refreshes whole sheet, so setting it to manual has drawbacks without gaining anything in my case.
Is it possible that your UDFs use volatile formulas such as
NOW,TODAY,RANDBETWEEN, OFFSET, INDIRECT, INFO, SUMIF, RAND or you declared your UDFs to be volatile?
In this case functions are recalculated if changes in any cells are made. For example if you fill hundred thousand lines with RAND it takes few seconds to recalculate after entering any value to a blank cell.
More on volatile formulas:
Volatile values in functions
More on volatile formulas in UDFs:
Excel Recalculation
Related
I want to update custom formulas added my Excel add in. Using Application/worksheet.Caclulate() updates whole sheet, but I want to update only those cells which are using my formulas.
I haven't tried this, but what if you used the technique described in Get formulas from a range of cells on the entire UsedRange of a worksheet. Then iterate through the returned array to find all the cells that have formulas matching one of yours. Then for each of those cells, call Calculate().
The Application object provides a method to force an immediate recalculation. Application.calculate(calculationType) starts a manual recalculation based on the specified calculationType. The following values can be specified.
full: Recalculate all formulas in all open workbooks, regardless of whether they have changed since the last recalculation.
fullRebuild: Check dependent formulas, and then recalculate all formulas in all open workbooks, regardless of whether they have changed since the last recalculation.
recalculate: Recalculate formulas that have changed (or been programmatically marked for recalculation) since the last calculation, and formulas dependent on them, in all active workbooks.
So, you could play with an argument to get the required piece recalculated.
I am still fairly new to VBA coding and for a while I have been having the same issue. In my code I am constantly jumping around an issue where I have a function or sub that performs a task or series of tasks which change any number of variables/values. I also have a number of excel cells that contain functions which retrieve single values - like "=Get_Density(B1,B2)" - where B1 and B2 might be mass and volume.
Most of my cells update whenever I change a value on my sheet that pertains to one of the variables within a function. For example if I change cell B1 this will automatically call the Get_Density() function to run, which automatically updates the cell.
What I want is when I have a function that has no input parameters or 'if statements' to control when a cell updates - like "Get_Density()" - with no parameters... How can I initiate my function externally.
This is just an example, but it is similar to what I am trying to achieve - lets say my values were to come from a userform that's opened from a button on an excel sheet. Lets also say I can input two values - mass and volume. Once I enter two values I click a button which says "Done" and then the program calculates the value for density and sets it equal to a variable in a separate module. Now how do I instantiate the cell which retrieves the value either on a button press or when the user form closes?
I have tried directly setting my cells from within VBA to the value that I want. My only problem with this is that if the position of where I want the value changes then I have to change every instance of it on my code. I have also tried checking for conditions within excel, but this only works for specific instances.
I can show code if needed, but I was hoping there was a method or function within VBA and excel that would achieve what I am looking for. I don't really have code that needs fixing.
add the following instruction at the begin of all functions that you want to be reevaluated after entering a new value to your worksheet
application.volatile
I have a UDF function within a xlam workbook that connects to a database and executes a query, based on the parameters entered. This function is going to be used hundreds of times within different workbooks. Since it is going to be used in a series of different workbooks, that is the reason why I used a xam workbook.
The issue is that using the UDF function so many times, slows the Recalculation down to much since it is recalculating when it doesn't need to. I was thinking about adding another indicator parameter in the UDF that if set to zero, it will just return the value of the cell before the Recalculation started. Is there anyway to do this? I was thinking about adding a conditional statement that would use something like application.caller.value to get the value.
I'm resurrecting some old scientific data from the early 2000s.
I need to locate the custom functions that allowed the data to be shown. The spreadsheet that I have is full of #REF! cells, as they are supposed to be calculated based on a custom-defined formula (here, called 'RESECTION').
How do I find this formula? If I can see the math it was performing, I will be able to use this old data, and extend our timeseries significantly.
The spreadsheet is an ".xlsm" document. There is an associated file that is ".XLM"; it provides some GUI-like functionality that is now broken, and I do not see how to access the commands (?) or other VBA that is inside.
I have not had success with this solution.
File with the VBA can be found here; SURVEY.XLM.
Problem is seen here; calling function from SURVEY.XLM. How do I access the formula within here?
I can see that the formula is in there; how do I see the calculation it performs?
RESECTION is a named range refering to cell A4 on the hidden Survey sheet.
In the VBE immediate window type thisworkbook.Sheets(2).visible = true and then thisworkbook.Sheets(2).select.
Cell Survey!A4 contains the value =RESULT(64).
The rest of the sheet contains the macros - first time I've seen or tried to use a filled in macro sheet.
I tried Ctrl+Fto find the definition of RESULT but it comes up with Macro error at cell [SURVEY.XLM]SURVEY!A364.
Scenario: I have a workbook that needs to be able to dynamically reference different worksheets based on user input. I was able to achieve this by using several INDIRECT functions and some other basic functions such as INDEX.
My problem is that the workbook is taking several minutes to load on a fairly powerful computer with no other strenuous processes running.
Question: Is there a simple way to optimize workbooks? I tried looking online for some standard methods to run through to catch unnecessarily strenuous processes to no avail. I am willing to use VBA if it would help speed the sheet up.
Thanks
Don't use INDIRECT or any other volatile functions (OFFSET, RAND, NOW, TODAY) in your workbooks if you can help it, because they get recalculated automatically pretty much at the drop of a hat...even if you’re doing something to the workbook that has absolutely nothing to do with those formulas whatsoever, such as:
Entering new data in a completely unrelated cell
Editing any existing, completely unrelated cells
Deleting or inserting a row or column anywhere in the workbook
Performing certain AutoFilter actions
Double-clicking a row or column divider (in Automatic calculation
mode)
Adding, editing, or deleting a defined name
Renaming a worksheet
Changing the position of a worksheet in relation to other worksheets
Hiding or unhiding rows (but not columns)
This means that if you have lots and lots of volatile functions like OFFSET or INDIRECT in your formulas, those formulas are going to be recalculating pretty much constantly. And if those formulas do some pretty resource-intensive number-crunching, Excel will be re-crunching those numbers pretty much every time you touch the mouse or keyboard. Yikes!
But that’s not the half of it: After Excel recalculates those functions, it merrily starts recalculating all cells downstream of them—regardless of whether those downstream cells have volatile functions in them. And regardless of whether anything actually changed as a result. And I mean all cells...not just the cells that directly point to your volatile functions but all the cells that point to those cells, and then the next bunch of cells that point to that last bunch, and so on and so on, all the way through your workbook. If you’ve used volatile functions at key points within a spreadsheet, pretty much the entire spreadsheet could be recalculating constantly. Double yikes!
But even this is not the worst of it! The problem isn’t limited to the workbook you happen to be doing something with at the time. Rather, every volatile function in every open workbook gets recalculated when you make a change in any workbook anywhere—even if there aren’t any formula links between those workbooks. So if you’ve got a very large spreadsheet model with volatile functions open—and then you start typing, say, a shopping list in another, it could take minutes for you to add each item to that shopping list, as everything you type in the shopping list triggers a new avalanche of unnecessary and pointless recalculation in the large spreadsheet model. Triple yikes!
The fact that each and every cell downstream of any volatile functions get recalculated is an important point to get your head around. Many people think that just the volatile functions themselves get recalculated. They are mistaken. It’s the subsequent forced recalculation of all cells downstream of all volatile functions in all open workbooks that causes you grief. In fact, even just one volatile function in one workbook could cause you grief if you have a very long calculation chain hanging off it.
What to use instead?
Use INDEX, or even better, CHOOSE.
Note that while INDEX isn’t fully volatile, it ain’t perfect: It still gets recalculated whenever the workbook opens. This is known as is semi-volatility, and it means that you still might notice recalculation delays when initially opening a complicated model that uses INDEX. Which is one of the reasons I go for CHOOSE
=CHOOSE(index_num,value1,value2,...)
Here’s the translation from Microsoft-speak into Jeff-speak:
=CHOOSE(Which area do you want?, First area, Second area, ...)
You need to translate your dropdown choice into a number in order to drive the Which area argument. But that’s no problem; you just use exactly the same setup as you do for INDEX—a lookup table that converts the output of the dropdown into an index number that tells CHOOSE which range you want.
If your input areas are turned into Tables, then great...you can just use the Table names.