Excel formulas with other sheet references not auto-calculating
Show older comments
I am using MATLAB to create an Excel spreadsheet. Within the data output to Excel, I have Excel formulas. For formulas that do no reference external sheets, they are calculated automatically when the spreadsheet is created (for example, column 'N' in the screenshot is a formula).
However, when I try to reference a different Excel sheet within the formula, the value in the Excel spreadsheet is '#N/A'. In Excel, if I click in the formula and then press enter, the formula works correctly (demonstrating that the format of the formula is correct).
In the screenshot, I clicked in the formula, and then pressed enter for cell P5, so the value is calculating correctly. However, I have not yet done that process for cell P6, so the value is '#N/A'.
How do I make Excel auto-calculate formulas that reference other sheets?

ML code to create the formula for Excel
c(5:end,2*numHex+7+i) = cellstr(strcat("VLOOKUP(D",rowNums,",CRETAinfo!A$2:",...
cdECol,"$",string(height(cretaData)+1),",",string(cdDColNum),",FALSE"));
ML code to write the cell array created to Excel
xlswrite(outFile,c);
Accepted Answer
More Answers (1)
Sreeram
on 10 Dec 2024
Hi Cole,
While I couldn't reproduce this behaviour in MATLAB R2022b, here's a potential workaround to help unblock the workflow.
To force Excel to recalculate all formulas, consider performing a ‘CalculateFull’ via MATLAB’s COM interface. Here is how it can be done:
Excel = actxserver('Excel.Application');
Excel.Workbooks.Open(fullfile(pwd, outFile));
Excel.CalculateFull();
Excel.ActiveWorkbook.Save();
Excel.Quit();
delete(Excel);
The ‘CalculateFull’ method recalculates all formulas in the workbook. More information about this function can be found in the following Microsoft documentation:
Additional details on using “actxserver” in MATLAB are available here:
If this solution does not help resolve the issue, sharing a MATLAB script with a minimal example might help the community to investigate further.
1 Comment
Cole Pratt
on 10 Dec 2024
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!