Erika
Erika

Reputation: 290

Identify last changed cell position in Google Sheets

How can I identify the last updated cell with Google Script? I have used this code so far, but if a change cell after the modification, the code identify the wrong cell position.

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];
 var cell = sheet.getActiveCell();

Somehow I should identify the last updated/changed cell position.

Thank you.

Upvotes: 2

Views: 2913

Answers (1)

Pierre-Marie Richard
Pierre-Marie Richard

Reputation: 2004

You should take a look at Event Objects, especially on onEdit(e) trigger

function onEdit(e){
  // Set a comment on the edited cell to indicate when it was changed.
  var range = e.range;
  range.setNote('Last modified: ' + new Date());
}

The e variable contains informations about the last modification on the Spreadsheet (Above, a example to get the modified range).

Upvotes: 2

Related Questions