Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Defined Functions NOT recalculating

I recently took a large, stable XLSM file, and split it apart into an XLAM and XLSX. Thousands of cells in the XLSX call (udfs) functions in the XLAM, and each such udf begins with the statement "Application.Volatile" (overkill, to force recalc).

The XLSX will NOT recalc with F9 thru Ctrl-Alt-Shift F9, nor with Cell.Calculate thru Application.CalculateFull. The XLSX cells are simply "dead" ... but ... I can reawaken them one by one if I hit F2 to edit the formula and then hit ENTER. Cells reawakened this way seem to stay awake, and recalc normally thereafter.

Has anyone encountered this strange behavior and are there any additional ways to force Excel to reconstruct the calc graph from scratch that I should try ?

One additional note in case it matters: I opened the XLAM and the XLSX via File Open, and have not installed the XLAM using the File ... Options ... Addins route - because in the past when I have done so, the minute you "uncheck" and installed XLAM then all the UDF references get replaced by full pathname links - pretty ugly. Alternatively if someone can outline a workaround for installing XLAM addins that doesn't create broken links everywhere I'll go with that.

like image 704
tpascale Avatar asked Apr 19 '11 16:04

tpascale


People also ask

Why a custom function is not working in Excel?

As for the custom ones, Excel cannot validate the VBA code and identify other cells that could also affect the result of the custom function. Therefore, your custom formula may not change when you make changes to the workbook. To fix the issue, you'll just need to use the Application. Volatile statement.

How do you refresh a user defined function in Excel?

Edit the cell containing the UDF. Simply entering the cell then pressing Enter without making changes should be sufficient to trigger an update. This causes Excel to always recalculate all formulas, regardless of whether it believes recalculation is required. This setting remains in effect until Excel is restarted.

How do I stop cells from recalculating in Excel?

To turn off automatic recalculation and recalculate open workbooks only when you explicitly do so (by pressing F9), in the Calculation options section, under Workbook Calculation, click Manual. Note: When you click Manual, Excel automatically selects the Recalculate workbook before saving check box.

Why are all my formulas returning 0?

This means that the cell doesn't contain any data. If the cell is blank, Excel will return a zero (0) value. You can use this feature to your advantage to make sure that cells with no data don't affect your formulas.


2 Answers

This works:

Sub Force_Recalc()
    Cells.Replace What:="=", Replacement:="=", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
like image 95
Greg Glynn Avatar answered Oct 23 '22 07:10

Greg Glynn


Figured it out - not sure why Microsoft has this "feature":

The condition arises when a virgin XLSX that uses an XLAM function is opened / created prior to opening the XLAM. In this case no amount of cajoling will cause the XLSX formulas to bind to and execute those XLAM functions, UNLESS you go into each cell & touch the formula bar & hit ENTER (or, as I discovered, do so en masse via a global replace - in my case all the funcs began w a "k", so globally replacing "k" with "k" fixed the error). The problem does not occur if the XLAM is opened first.

like image 26
tpascale Avatar answered Oct 23 '22 07:10

tpascale