Time stamp update

Hi John, sorry for the late reply but here’s the working script.

// The column you want to check if something is entered.
var COLUMNTOCHECK = 2;
// Where you want the date time stamp offset from the input location. [row, column]
var INITIAL = [0,1];
var LATEST = [0,2];
// Sheet you are working on
var SHEETNAME = 'Change test'
 
function onChange(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  //checks that we're on the correct sheet.
  if(sheet.getSheetName() == SHEETNAME) { 
    var selectedCell = ss.getActiveCell();
    //checks the column to ensure it is on the one we want to cause the date to appear.
    if(selectedCell.getColumn() == COLUMNTOCHECK && selectedCell.getValue() == true) { 
      var initialcell = selectedCell.offset(INITIAL[0],INITIAL[1]);
      var latestcell = selectedCell.offset(LATEST[0],LATEST[1]);
      if(initialcell.getValue() !== ''){
      latestcell.setValue(new Date());}
      else {
      initialcell.setValue(new Date());}
      }
  }
}

The setup: a spreadsheet with column B containing the check boxes, column C as initial change and column D as latest change.

image

Input your script into the script editor, notice the fields you have to change are:

  • var COLUMNTOCHECK = 2 => Change number 2 to whatever column contains your checkbox. Here it’s column B, hence number 2.
  • var SHEETNAME = ‘Change test’ => Change ‘Change test’ to your sheet’s name.

Then navigate to Edit > Current Project’s Triggers and set the conditions like what @Mrinal_Chakraborty showed.

A demo on how it works.

ezgif-1-4a0024634334

2 Likes