0
votes

I am trying to figure out how to create a date stamps, that get modification anytime a change is done in a cell. I am also very new to Google App Script (everybody needs to start somewhere).

I found the following code on how to create the date stamp :

function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Test" ) { //checks that we're on Sheet1 or not
var r = s.getActiveCell();
if( r.getColumn() == 8 ) { //checks that the cell being edited is in column A
var nextCell = r.offset(0, -1);
if( nextCell.getValue() === '' ) //checks if the adjacent cell is empty or not?
nextCell.setValue(new Date());
}
}
}

which work for adding the date stamp in the column G, for any data filled in column H.

But if I wanna change the data in H2 for any value, the date in G2 stay the same.

Anybody could make suggestions please.

1
Welcome. Maybe you should start by reading developers.google.com/apps-script/guides/sheets - Rubén
I don't understand this But if I wanna change the data in H2 for any value, the date in G2 stay the same. Can you provide some images show examples of what you want? - Cooper

1 Answers

0
votes

Your code includes the condition if( nextCell.getValue() === '' )

This means that a time stamp will only be set if nextCell (the cell in column G) is empty

If you want the timestamp to updated every time a value in column H is changed -remove this condition.

So:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Test" ) { //checks that we're on Sheet1 or not
    var r = s.getActiveCell();
    if( r.getColumn() == 8 ) { //checks that the cell being edited is in column A
      var nextCell = r.offset(0, -1);
      nextCell.setValue(new Date());
    }
  }