If used in automatic calculation mode (our preferred mode) Excel recalculates pretty much every time anything happens. Luckily Excel uses some pretty sophisticated rules to work out which parts of a workbook it actually needs to calculate. If you edit a cell, then roughly speaking Excel will only recalculate any cells that depend on that one and any that depend on those ones, and so on.
There are some functions where Excel cannot tell if their precedents have changed. The most obvious example is the INDIRECT function. This takes a string, tries to convert it to an address, if it succeeds it returns the value found at that address. If you try to audit an INDIRECT function you will see that Excel does not evaluate the passed in argument and report the result as a dependent, it just shows none. Other functions like this include OFFSET, RAND, NOW among others.
These functions are known as volatile. Because Excel can't use its smart calculation rules to know when it doesn't need to calculate them, it calculates them every time it calculates.
For a small number of formulas the performance impact will not be noticeable. If a workbook contains a large number of volatile functions, even small edits in unconnected areas will result in a significant recalculation. Bear in mind Excel calculates all open workbooks, not just the active one that is being edited.
VBA User Defined Functions (UDFS) are sometimes set up as volatile (by including the line
Application.Volatile = true
at the start of the function). Codematic do not recommend this, but some people feel the advantages outweigh the disadvantages (it can reduce the number of passed in parameters making it easier for end users, but at a cost of calculating with every minor change).
To get a sense of the cost of marking a function as volatile, or using volatile Excel functions we built a simple fast xll UDF in C. The function just keeps count of the number of times its been called. Its registered with Excel as volatile so it calculates and increments every time Excel does any sort of calculation for whatever reason.
The function is trivial:
long int lCount = 0;
EXPORT long int VolatileCalcCount ( void )
The results are interesting - in a normal spreadsheet editing session Excel can calculate 200 times or more an hour. If there are lots of volatile functions, or some slow ones (any VBA UDF is likely to be slow) that could mean anything from a noticeable pause when entering data, to an unusable many seconds (or minutes!) delay. One solution often suggested is to turn calculation to manual. The codematic view is that defeats the object of using a spreadsheet, and most of the time will lead to someone somewhere using uncalculated values by mistake.
To use the xll, simply double click it to open it then enter the following formula in a cell somewhere:
You can also find it under Codematic Functions in the Function Wizard.
The calculation counter xll is a free download available from here.
Any comments, feedback or suggestions welcome here.