Alister
Alister

Reputation: 21

Automatically updating google spreadsheet with modified dates

I've been trying get google spreadsheet to add data into a cell automatically when another cell is edited, however I can only seem to make the onedit function work globally.

Specifically, if B2, B3, B4 etc. was edited, I would like N2, N3, N4 etc. to automatically fill with a timestamp, or the user's name.

I have been able to get the trigger working, but I cannot get an output to my cell. Here's the macro I've set up-

function onedit(event) 
{
  var ss = SpreadsheetApp.getActiveSheet();
  var rr  = SpreadsheetApp.getActiveRange();

  
  if(ss.getIndex()!= 2)
   return;
 
  var firstRow = rr.getRow();
  var lastRow = rr.getLastRow();
  
  ss.getActiveCell().setValue(today());
}

Using setValue(today) does not seem to automatically update the cell.

Upvotes: 1

Views: 1755

Answers (1)

ScampMichael
ScampMichael

Reputation: 3728

function onEdit(e) {
  var s = e.source.getActiveSheet();

  if( s.getIndex()== 2 ) {
    var r = s.getActiveRange();
    if( r.getColumn() == 2) {
      s.getRange(r.getRow(),14).setValue(new Date());

    }
  }
}  

Upvotes: 3

Related Questions