Most Valuable Professional

View Jan Karel Pieterse's profile on LinkedIn subscribe to rss feed
Subscribe in a reader

Subscribe to our mailing list

* indicates required

Audit !!!

Check out our RefTreeAnalyser
the ultimate Excel formula auditing tool.


Excel VBA Masterclass (English)
Excel VBA for Financials (Dutch)

Third party tools

Speed up your file

The best tool to optimise your Excel model!

Repair your file

Stellar Phoenix Excel Repair
Best tool to repair corrupt Excel sheets and objects
Home > English site > Articles > Circular References > Calculation settings
Deze pagina in het Nederlands

Working with Circular references in Excel

Circular references and calculation settings

If you want to work with circular references, the calculation settings of Excel are very important. This page gives you some pointers!

Calculation settings

The first thing that needs to be done if you want to assure your model works, is to turn on iterative computation of the file.

Iteration settings in Excel 2010
Iteration settings in Excel 2010

It is up to you to decide how many iterations you want Excel to do before it stops, or what precision you need before Excel stops (whichever comes first). As soon as you check the box "Enable Iterative calculation", Excel will do a calculation of your model. After saving the file, if you open the file again you should no longer get the circular reference warning message.

If you are troubleshooting your calculation, set Maximum Iterations to 1. This gives you the opportunity to step through the calculations one at the time by repeatedly hitting the F9 key.

Which calculation settings apply

I often get this question: I have checked the "Enable Iterative calculation" box on my file. Why do I still get the circular reference warning? To be able to understand what causes this it is important to know how Excel handles its calculation settings.

Application wide settings

Calculation settings are application-wide. That is, if workbook A needs manual calculation and workbook B needs automatic calculation and you have both workbooks open, Excel's current setting will apply to both workbooks. The same goes for the iterative calculation settings: they apply to all workbooks in your Excel session.

When you save a workbook, whichever calculation setting was applied at that time is saved with the workbook.

First-come first-serve

Excel will apply the calculation settings of the first workbook you open in a session. So if you first open workbook A (which had iteration disabled when it was last saved) and then Workbook B (with iteration enabled when it was last saved), Excel will keep iteration disabled. This explains why you do get the circular reference warning on that workbook.

Warning: When you save your workbook, the calculation settings that are currently in effect are saved with the file. This means that if you have previously set up iterative calculation and the max iterations and max change, these settings may be overwritten with the current settings.

Making sure you have the calculation settings you need

There are several ways to ensure your workbook calculates as expected:

Always open as the first workbook

Well, that one is obvious enough. Of course if your model is used by other people as well, this is not exactly fool-proof. Your users would have to be made aware of this situation, but chances are very high your calculation settings will get overwritten at some point, making your model unreliable. And even if you're the sole user, this is a big risk.

Use a bit of VBA to control calculation settings

A more reliable way to control the calculation settings is by adjusting them when your workbook loads. This means you will have to add macro's to your file, but this is straightforward enough.

I assume the file with the circular references is already open.

Open its ThisWorkbook module by double-clicking on it in the project explorer as shown below:

The Project explorer in the VBA Editor

The Project explorer in the VBA Editor

Paste this code into the code window that opens up and modify the calculations settings so they match what you need.

Option Explicit

Private Sub Workbook_Open()
    With Application
        .Calculation = xlCalculationAutomatic
        .Iteration = True
        .MaxIterations = 100
        .MaxChange = 0.001
    End With
End Sub

Now save your file (if you are using Excel 2007 or up, make sure you change the file-type to one that can hold macro's, otherwise the macro code is discarded after you close your file!)



Showing last 8 comments of 21 in total (Show All Comments):


Comment by: Sasha (26-2-2016 23:54:27)


I am currently saving registry keys to allow toggling from one workbook to another (and thus modifying the application settings from the original settings to the specific ones) on Activate and Deactivate events. Is this a good route to go for in your opinion?


Comment by: Jan Karel Pieterse (27-2-2016 11:37:53)

Hi Sasha,

I'd say if your solution works reliably and meets your business needs, then it is a good solution. As simple as that.


Comment by: Sasha (1-3-2016 01:48:29)


Thanks for your input. Furthermore, I couldn't help but notice that that you are setting the calculation to "xlCalculationAutomatic". As I consider myself mostly a power coder, I fail to realise why this is necessary and would like to hear your thoughts on doing this instead of simply setting it to xlCalculationManual on startup and triggering the calculations on events when necessary with "Application.CalculateFull". Thank you again!


Comment by: Jan Karel Pieterse (1-3-2016 21:23:47)

Hi Sasha,

I think because I expect that that will ensure Excel handles the iteration properly. I expect it doesn't make much of a difference, but I haven't tested this to be honest.


Comment by: Harry (29-3-2016 07:05:53)

I am using Circular reference formula in one column "m" i.e =m7+f7. But any Changes made to the column 'f" in any other rows also automatically increases the value in the circular reference column "m". Any idea why?


Comment by: Jan Karel Pieterse (29-3-2016 09:30:45)

Hi Harry,

This is because circular references are in fact volatile, meaning they will recalculate on every calculation.


Comment by: Jerry Hartis (2-5-2016 03:37:55)

In working with a chemical plant with a very large recycle loop, if an error occurs any where in the calculation, it can be a large problem and very hard to fix.

To prevent the whole workbook going to #error, we have closed the circular calculation with a macro that sets the value of the first cell in the large loop with the value of the last cell. We run the macro a few iterations until the calculation converges. With this, Excel doesn't even detect the circular calculation and the whole spreadsheet does not turn to #error from a bad keystroke. Repeat as needed, if there are more circular calculations add them to the same macro.


Comment by: Jan Karel Pieterse (2-5-2016 06:46:43)

Hi Jerry,

Thanks for your comments. This is precisely what I suggest on the next page:


Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I do this" Excel question, then I advise you to ask your question here:

Please enter your name (required):

Your e-mail address (optional, will only be used to inform you when your comment is published or to respond to your question directly):

Your request or comment (max 2000 characters):

To post VBA code in your comment, use [VB] tags, like this: [VB]Code goes here[/VB].

I give permission to process this data and display my name and my comment on this website accoring to our Privacy Policy.