Search code examples
typescriptgoogle-apps-scriptgoogle-sheetsspreadsheet

Automatically " + insert 1 row above" a cell once data is entered into the cell


In google sheets:

After I enter a value into cell A3 I would like it to automatically push the content of this row to A4 and leave A3 blank for another entry.

Image 1 would be what I have and Image 2 is what I would like to automatically happen. TIA..this is my first go at something like this so please send the actual script or explain it like I'm 5 years old...

Image 1 Image 2

function onEdit(e) {
  var sheet = SpreadsheetApp.getActive().getSheetByName(CopyofCoastalNon-RCMInvoiceTracking);
  var editedRange = e.range;
  if (editedRange.getA1Notation() === "A3") {
      sheet.insertRowBefore(2);
  }
}

Solution

  • function onEdit(e) {
      const sh = e.range.getSheet();
      if(sh.getName() == "CopyofCoastalNon-RCMInvoiceTracking" && e.range.columnStart == 1 && e.range.rowStart == 3) {
        sh.insertRowBefore(3);
      }
    }