Skip to content Skip to sidebar Skip to footer

How Do I Automatically Set A Google Sheets Cell To The Current Date On Editing Its Row?

I have a Google Spreadsheet that I want to automatically set the value of a 'Date' cell whenever I edit a row where the date has not already been set. As far as I know the Google S

Solution 1:

I suppose you did not set the triggers. In the Script editor, go to Resources -> Current project's triggers Select your function name (in this case onEdit) and set the Event as From Spreadsheet -> onEdit

Save it and you are done.

Edited Solution

Okay there is problem in your code too. I missed that earlier.

getCell is a function of class range and NOT class sheet. You should use getRange instead. Here is a code that should work. You can edit it as per your requirements.

function onEdit(event){
  var sheet = event.source.getActiveSheet();
  var debugCell = sheet.getRange(10,10);
  debugCell.setValue("DEBUG CELL"); // if anything works, this should show up... but it doesn't :Cvar editedCell = sheet.getActiveCell();
  var dateCol = 1;
  var dateCell = sheet.getRange(editedCell.getRow(), dateCol);

  debugCell.setValue(editedCell.getColumn());

  if(!dateCell.getValue() && editedCell.getColumn() != dateCol){   
    dateCell.setValue(new Date());
  }
}

Post a Comment for "How Do I Automatically Set A Google Sheets Cell To The Current Date On Editing Its Row?"