Excel-Volatile Functions

Volatile Functions
A volatile function is simply a function which will recalculate every time any action is performed on excel, such as entering data, changing column widths etc.(one of the few actions that will not trigger a recalculation of a volatile function is changing the formatting of a cell, unless you do this via Paste Special—Formats. Some examples of volatile functions are
Excel’s Volatile Functions.

Some of Excel’s functions are obviously volatile: RAND(), NOW(), TODAY()
Others are less obviously volatile: OFFSET(), CELL(), INDIRECT(), INFO()
Some are volatile in some versions of Excel but not in others: INDEX()became non-volatile in Excel 97.
A number of functions that are documented by Microsoft as volatile do not actually seem to be volatile when tested:
and CELL("Filename") IS volatile although a MSKBN article says its not.

Using a volatile function in a formula will flag the cell containing the formula as volatile, even if the volatile function never gets executed:
=IF(1<2,99,now()) contains ="NOW()" then ="IF(1<2,99,A1)">

Dependents of Volatile functions.
Direct dependents of volatile functions are always recalculated:If A1 contains =NOW() and A2 contains =A1 and A3 contains =A2 then both A2 and A3 will be recalculated at each recalculation.

Indirect dependents of volatile functions are not always recalculated:

If A1 contains =NOW(), and A2:A5 contain the numbers 2 to 5 then
=INDEX(A1:A5,1,1) is directly dependent on volatile cell A1 and will always be recalculated.
=INDEX(A1:A5,3,1) is only indirectly dependent on volatile cell A1 and will NOT always be recalculated, but it will be recalculated once if for example cell A5 is changed even though the answer will not change.

IF(), CHOOSE(), AND(), OR()
The IF and CHOOSE functions only execute ONE of the available choices. This is called short-circuiting:
If you create UDFs One, Two and Three each of which contain a debug.print or MsgBox statement so that you can see what is being executed then:
=IF(True,One(),Two()) will only execute the One() udf, and not the Two() udf.
=CHOOSE(2,One(),Two(),Three()) will only execute the Two() udf and not the One() or Three() udfs.
The AND and OR functions always execute ALL the available choices:
If the One(), Two() and Three() UDFs return 1,2 and 3 respectively then:
=AND(One()=2,Two()=2,Three()=3) will always execute the Two() and Three() UDFs even though One()=2 will always be false.
=OR(One()=1,Two()=1,Three()=1) will always execute the Two() and Three() UDFs even though One()=1 will always be true.

Volatile only at Workbook Open

References to UDFs where the UDF itself is located in an XLA or external workbook are flagged as dirty when the workbook containing the reference is opened: if calculation is Automatic they will be recalculated at workbook open, if calculation is Manual they will be recalculated at the next recalculation.
Using INDEX as the second part of a range reference, for example A$2:INDEX(A$2:A$8,7,), will also cause the reference to be flagged as dirty when the workbook is opened. (Thanks to Bill Wood for spotting this).
Because a cell has been flagged as dirty the workbook will also be flagged as Unsaved so you may get an unexpected prompt to Save the workbook when closing it.

Conditional Formats are volatile.

Because conditional formats need to be evaluated at each calculation any formulae used in a conditional format is effectively volatile. Actually conditional formats seem to be super-volatile: they are evaluated each time the cell that contains them is repainted on the screen, even in Manual calculation mode, although VBA functions used in conditional formats will not trigger breakpoints when executed by the repaint.
Volatile Actions: Actions that trigger calculation
Selecting any filtering criteria when using Autofilter will flag ALL the formulae in the autofilter range as uncalculated, even if none of their precedents have changed and even if you select exactly the same filter criteria as before. This can cause Autofilter calculation to be extremely slow.
Clicking Row or Column Divider
If calculation is set to Automatic clicking or doubleclicking a row or column divider will trigger a recalculation. But manually changing the height or width of a column or row will NOT trigger a recalculation.
In Manual mode these actions do not flag the workbook as requiring calculation.
Inserting or Deleteing Rows, Columns or Cells
Insert or Delete Rows or Columns or Cells anywhere on a Sheet, even to the right or below the Used Range.AND – The Worksheet contains formulae which:
EITHER - Contain Names referring to this Worksheet or other WorksheetsOR – Refer to other WorksheetsOR – Are referred to by other Worksheets
Then these formulae become flagged as uncalculated.
Adding, Changing or Deleting Defined Names
Any action taken to add, delete, change or alter a defined name or its refersto property will trigger a recalculation.
Renaming Worksheets and Changing Worksheet Position
Changing the name of a worksheet or moving it will trigger a recalculation in Automatic mode.In Manual calculation mode, the statusbar will show "Calculate" ONLY if any formulae on any other sheet refer to the sheet with the changed name/position.
Deleteing Worksheets, but not Adding Worksheets
In Automatic mode deleting a worksheet will trigger a recalculation, but adding a worksheet will not.
Hiding or Unhiding Rows in Excel 2003
In Excel 2003 hiding or unhiding rows will flag the selected rows as uncalculated, even if no rows were actually hidden or unhidden. If calculation is automatic this will trigger a recalculation. This behaviour is a change from previous versions. Hiding or unhiding columns does NOT flag the column as uncalculated.
Probably the reason for the change is that the SUBTOTAL function in Excel 2003 has an option to include or ignore hidden rows, so Excel needs to be able to trigger a dependency recalculation by dirtying the cells when a row is hidden or unhidden.
Opening a .CSV file
Whenever you open a .CSV file, either through VBA or File-->Open, a recalculation of all open workbooks will be triggered, even if calculation is in Manual. Switching off .EnableEvents does not stop this recalculation. The only way I have found to prevent this recalculation from happening is to use VBA to switch Worksheet.EnableCalculation to False for each worksheet that you do NOT wabt to be calculated.

Blog Widget by LinkWithin

Search this blog..