Skip to content

Move references in data validation and conditional formatting formulas - #422

Merged
MathNya merged 2 commits into
MathNya:masterfrom
jayhemnani9910:fix/move-rule-formulas
Nov 27, 2026
Merged

MathNya merged 2 commits into
MathNya:masterfrom
jayhemnani9910:fix/move-rule-formulas

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Follow-up to #417, which moves a data validation's range on row and column edits but not the references in its formulas. Conditional formatting has the same gap:

H1:H3 = Red, Green, Blue; list validation on A1:A5 with formula1 $H$1:$H$3
conditional format on B1:B5: $B1>$F$1
insert_new_row(1, 2)
sqref moves to A3:A7 / B3:B7, but formula1 stays $H$1:$H$3 and the rule stays $B1>$F$1

The dropdown then lists blank, blank, Red, and the rule tests the wrong row.

formula1 / formula2 of a data validation and the cfRule formula are now passed through the same insert/remove adjustment as cell formulas (two small helpers in helper/formula.rs), with the worksheet's title, so Sheet1!$H$1:$H$3 on Sheet1 moves too and references to other sheets stay. A literal list ("a,b,c") is left as is.

Built on #421, since $ references only move with that change.

Tested: new row_edits_move_data_validation_formulas and row_edits_move_sheet_qualified_validation_formulas fail without the change, plus unit tests for the helper (own-sheet, other-sheet, literal list); cargo test passes. Reading an xlsx with both rules, insert_new_row(1, 2) and writing it back: <formula1>$H$3:$H$5</formula1>, <formula1>$J$3</formula1>, <formula>$B3&gt;$F$3</formula>, <formula>$F$3</formula>.

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.
Inserting or removing rows and columns moved the range a data validation
or conditional format applies to, but not the references in its
formulas, so a list validation fed from $H$1:$H$3 or a rule like
$B1>$F$1 pointed at the old cells. Run formula1/formula2 and cfRule
formulas through the same adjustment as cell formulas; references to
other sheets are left alone.
@MathNya

MathNya commented Nov 27, 2026

Copy link
Copy Markdown
Owner

@jayhemnani9910
I'll merge this one too.

@MathNya
MathNya merged commit 7e8d1fb 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