Skip to content

Move absolute references when inserting or removing rows and columns - #421

Merged
MathNya merged 1 commit into
MathNya:masterfrom
jayhemnani9910:fix/insert-remove-moves-absolute-refs
Nov 27, 2026
Merged

MathNya merged 1 commit into
MathNya:masterfrom
jayhemnani9910:fix/insert-remove-moves-absolute-refs

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Inserting or removing rows and columns never moves absolute ($) references in formulas, so they read the wrong cells afterwards:

H1=1, H2=2, A1: =SUM($H$1:$H$2), A2: =SUM(H1:H2)
insert_new_row(1, 2)
A1: =SUM($H$1:$H$2)   -> now sums two blank cells
A2: =SUM(H3:H4)

H1..H5 = 10..50, A1: =$H$4, C1: =VLOOKUP(2,$G$2:$H$5,2,FALSE)
remove_row(3, 1)
A1 stays =$H$4 (now 50 instead of 40), C1 stays $G$2:$H$5

In Excel and LibreOffice $ only fixes a reference when a formula is copied or filled; inserting or deleting cells moves every reference to the moved cells. shift_coordinate (used only by adjustment_insert_formula_coordinate and adjustment_remove_formula_coordinate) skipped the locked part. It now shifts both parts and keeps the $. The copy path for shared formulas goes through adjustment_formula_coordinate and still leaves $ references alone. On the same insert, the Print_Area defined name already moved from $A$1:$F$5 to $A$3:$F$7; formulas now match it.

#410 kept the old behaviour for locked parts ("Locked ($) parts are still left alone, as before"); this changes that.

shared_adjustment_preserves_quoted_sheet inserts a row above '(1)'!$E$38, so its expected reference becomes $E$39; the test is about keeping the quotes on the sheet name.

Tested: new insert_and_remove_move_absolute_refs fails without the change; cargo test passes. Reading an xlsx, insert_new_row(1, 2) and writing it back gives SUM($H$3:$H$4) and SUM(H3:H4). Not changed here: a range that starts on a removed row moves up a row ($G$2:$H$5 after removing row 2 becomes $G$1:$H$4), which is how relative references are already handled.

shift_coordinate left the locked ($) column and row of a reference where
they were, so after insert_new_row or remove_row, =SUM($H$1:$H$2),
VLOOKUP(x,$A$2:$B$100,...) and =$H$4 read the wrong cells. In Excel $
only fixes a reference when a formula is copied or filled; inserting or
removing cells moves it like any other. The copy path (shared formulas)
uses adjustment_formula_coordinate and still keeps $ references.

shared_adjustment_preserves_quoted_sheet inserts a row above E38, so its
expected reference is now $E$39; the test is about the quoted sheet name.
@MathNya

MathNya commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@jayhemnani9910
Thank you.
It looks fine, so I'll merge it.

@MathNya
MathNya merged commit 0fad372 into MathNya:master Nov 27, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants