Preserve a Formula Result Without a Circular Reference in Excel
Question details
Retain a previous calculated value while a condition changes, without iterative calculation or manual copying.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet should display a live value while a condition is TRUE and preserve the last cached value when it becomes FALSE.
- Observed behavior
- The desired result is a persistent value stored separately from the formula, with no formula referring to its own result.
Choose an unused cache cell that can be overwritten, and make sure the live calculation does not depend on that cache cell. The VBA approach requires desktop Excel, a macro-enabled workbook, and permission to run macros.
Cache the Last Live Value with an Excel Worksheet Event
Use a separate cell and a VBA calculation event to retain the last value recorded while the condition is TRUE.
A worksheet formula cannot remember its own previous result. In this example, F4 contains a Boolean condition, F5 contains the live value, F6 stores the cached value, and G5 displays the result. The formula in G5 is not circular unless one of its dependencies leads back to G5.
The event updates F6 when the worksheet recalculates and F4 is TRUE. It skips errors in F5, so the cache keeps its last non-error value. This is not a historical log: test the timing carefully if F4 and F5 change together or are controlled by other macros.
On the target worksheet, put TRUE or FALSE in F4 and the live value or formula in F5. Reserve F6 for the cache; the macro will overwrite its contents.
In G5, enter =IF(F4,F5,F6). Keep F5 independent of F6 and G5 to avoid a circular dependency or a VBA feedback loop.
Press Alt+F11, find the workbook in Project Explorer, and double-click the worksheet containing F4:G5. Paste the following code into that worksheet's code window: Private Sub Worksheet_Calculate() Dim previousEvents As Boolean Dim liveValue As Variant Dim cachedValue As Variant previousEvents = Application.EnableEvents On Error GoTo CleanUp Application.EnableEvents = False If VarType(Me.Range("F4").Value2) = vbBoolean Then If Me.Range("F4").Value2 = True Then liveValue = Me.Range("F5").Value2 cachedValue = Me.Range("F6").Value2 If Not IsError(liveValue) Then If IsError(cachedValue) Then Me.Range("F6").Value2 = liveValue ElseIf VarType(liveValue) <> VarType(cachedValue) Then Me.Range("F6").Value2 = liveValue ElseIf liveValue <> cachedValue Then Me.Range("F6").Value2 = liveValue End If End If End If End If CleanUp: If Err.Number <> 0 Then Debug.Print Err.Description Application.EnableEvents = previousEvents End Sub
Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). Enable macros if prompted, set F4 to TRUE, change F5, and recalculate with F9 if needed. Then set F4 to FALSE and confirm that G5 displays the value stored in F6.

Work with Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Office formats, making it easy to move everyday workbook tasks to WPS. It does not fix Excel's VBA calculation behavior; macro support can vary by WPS version and platform.

Frequently Asked Questions
Can an Excel formula remember its previous result by itself?
No. A standard formula recalculates from its inputs and cannot store its own previous result. Use a separate storage cell with VBA or another external storage method if iterative calculation is not an option.
Is =IF(F4,F5,F6) a circular reference?
Not when it is entered in G5 and F4, F5, and F6 do not depend on G5. It becomes circular if the formula refers to its own cell directly or through a chain of dependencies.
Why does the cached value not update?
Check that macros are enabled, the code is in the correct worksheet's code window, and F4 contains the Boolean value TRUE. The code runs on worksheet calculation; if calculation is manual, press F9 while F4 is TRUE.
Will the cached value remain after I close the workbook?
Yes, if you save the workbook after F6 has been updated. Save it as an Excel Macro-Enabled Workbook (*.xlsm) to keep the VBA code as well.
What happens if F5 contains an error?
The sample code skips an error value in F5 and leaves the previous value in F6 unchanged. Check the formula in F5 and recalculate after correcting it.




