Undo not working on cells referenced in Code

Hi, I am unable to use the undo/redo command on cells that have been referenced in Anaconda Code. Is there a fix for that?

tl;dr Use Isolated Mode and be aware that adding or modifying Anaconda Code cells will break the undo stack. When those same cells update values because their dependencies changed, it won’t break the undo stack.


There is a long history of how Javascript add-ins interact with the Excel undo/redo stack. See official documentation here that explainswhy Javascript add-ins break the undo stack.

However, there has been some improvements by Microsoft earlier this year (Mar 2024) that improve the situation for custom functions (i.e. when the grid calls the add-in and gets back a value).

The result is that:

  1. When you modify an Anaconda Code cell by editing and clicking “Save and Run”, the undo stack is broken.
  2. Once written, if the value of an isolated Anaconda Code cell changes because its dependencies change, the undo stack is not broken.
  3. When the value of a linked Anaconda Code cell changes because its dependencies change, the undo stack is unfortunately still broken.

#1 is a result of the add-in modifying the workbook. There isn’t any way to work around this.

#2 is the happy path. Once written, the Python calculations will update and won’t break the undo stack.

#3 is subtle. To make linked mode work – in which all Python cells runs whenever any Python cells runs – we manually trigger the first linked Anaconda Code cell to run when we detect a change to any linked cell. Because this trigger is interpreted as the add-in directly writing to the workbook, it breaks the undo stack. There is no workaround for this.

1 Like