XL: Custom Function May Not Calculate Expected Value (221048)
The information in this article applies to:
- Microsoft Excel 2000
- Microsoft Excel 2002
This article was previously published under Q221048 For a Microsoft Excel 97 version of this article, see 223312.
For a Microsoft Excel 2001 for Mac and Excel 98 Macintosh Edition version of this article, see 223314.
SYMPTOMS
When you calculate your worksheet, some cells may appear to have calculated the wrong value.
CAUSE
This problem occurs when the following conditions are true:
- A cell on the worksheet contains a custom function.
-and-
- The custom function contains one or more arguments that refer to a range of cells on the worksheet.
-and-
- The result of the custom function depends on more cells than it directly references.
This behavior is by design of Microsoft Excel. When Excel calculates the cell containing the custom function, it recalculates all cell ranges that are passed as arguments to your custom function. If the result of your function depends on cells that are not explicitly referred to by the function, then those cells may not be recalculated.
WORKAROUND
To work around this problem, use any of the following methods.
Method 1: Modify Your Function So That All Relevant Cell Ranges Are Passed
Modify your function to accept as arguments all of the cells necessary to calculate the result of the function.
Method 2: Make Your Custom Function VolatileMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
If you make your custom function volatile, this problem will not occur. To
make your custom function volatile, add the following line of code to the
function:
Application.Volatile
NOTE: If you make your custom function volatile, it will recalculate every time you make a change to a value or recalculate an open workbook. This could impact the performance of your worksheet model.
Method 3: Force Excel to Recalculate All Open Workbooks
Press CTRL+ALT+F9 to recalculate the values in all open workbooks.
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kbdtacode kbpending kbprb KB221048 |
---|
|