Google Apps Script: Update Column When Row Is Modified/Edited

April 6, 2019

At Google Sheets, click Tools -> Script Editor.

The following code will update Column J to 1 when row is edited/modified.

function onEdit(e) {
  var range = e.range;
  var sheet = range.getSheet();
  var updateCol = "J";
  var updateCoIndex = updateCol.charCodeAt(0) - 64


  /*
  // limit to specific sheet
  // sheet.getSheetId()
  if (sheet.getName() !== sheetName) {
    return;
  }
   */

  if (range.getColumn() != updateColIndex) {
    var row = range.getRow()
    // Update Column J to 1 when row is edited
    var updateRange = sheet.getRange(updateCol + row.toString());
    updateRange.setValue(1);
    // range.setNote('Last modified: ' + new Date());
  }
}

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.