'Is there a way to edit a referenced cell in Google Sheets?

Data

I have a Google Sheet with a column containing the following names:

A B
Bob Alice
Dan Bob
Alice Dan

The values in A are raw text; the values in B are populated by the formula =SORT(A:A) written in cell B1.

Question

Is there a way to edit the values in Column B and have those changes reflected in A, even though they are just references?



Solution 1:[1]

Try, with in B1 the formula ={"sorted list";sort(A2:A)}

function onEdit(e) {
  var r = e.source.getActiveRange()
  if (r.getColumn() == 2 && r.getRow() > 1) {
    var sh = e.source.getActiveSheet()
    var values = sh.getRange('A1:A' + sh.getLastRow()).getValues().flat()
    if (values.indexOf(e.oldValue) != -1) {
      sh.getRange(+values.indexOf(e.oldValue) + 1, 1).setValue(e.value)
    }
    r.clearContent()
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Steelson