Skip to content

Refactor to LET: rewrite a formula into a tidy LET #201

@jimmytacks

Description

@jimmytacks

Overview

New /Refactor slash command that takes the active cell's formula — LET or not — and rewrites it as a tidy LET where every cell ref and range appears as a single value binding. The author then runs /LET to LAMBDA as the next step. Mirrors the /Gather → /LET to LAMBDA two-stage pattern.

Worked example

Active cell:

=IF(A1<10, IF(A1>2, SUM(B1:B5), 0), SUM(B2:B6))

After /Refactor:

=LET(
    input1, A1,
    input2, B1:B5,
    input3, B2:B6,
    IF(input1<10, IF(input1>2, SUM(input2), 0), SUM(input3)))

Also handles the "messy LET" case: extracts refs from inside calculation bindings, merges duplicate value bindings (first name wins), and reorders inputs-before-steps.

Spec and plan

Implementation Plan

4 PR-sized slices, sequenced. PR 1 is a tracer bullet — end-to-end on non-LET formulas with cell refs / ranges / spill — so the feature is exercisable in Excel from day one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions