Google-sheets – How to update one column based on the value of another using a script

google sheetsgoogle-apps-script

Script no Formula

I would like to change the value in the D column based on the value of the C column if the cell in C contains "YES", using a script instead of a formula.

Sample spreadsheet

Best Answer

This function will update column D to "Done" when column "C" is updated to "Yes"

function onEdit() {
   var s = SpreadsheetApp.getActiveSheet();
   var r = s.getActiveCell();
      if( r.getColumn() == 3 && r.getValue() == 'Yes')
      var nextCell = r.offset(0, 1);
      nextCell.setValue("Done");
}