onEdit help

9 views
Skip to first unread message

danprend...@gmail.com

unread,
Jun 22, 2022, 1:51:41 PM6/22/22
to Google Apps Script Community
I have a sheet that I have a button set up to run.  However, buttons don't seem to run while using a mobile app.  I've been looking at using the onEdit instead, but I can't even get this simplest function to work;

function onEdit(e) {


/**
SpreadsheetApp.getActiveSpreadsheet().getRange(e.range.getRow(), 3).setValue(new Date());

*/

SpreadsheetApp.getSheetByName('Sandbox').getRange(e.range.getRow(), 3).setValue(new Date());

}

I've tried both of the examples at separate times, but nothing.  The intent is to simple recognize a cell was updated, and put the date/time in the 3 column (column C).  

I only have 1 onEdit script, and I am the owner of the spreadsheet, with all rights.  Any thoughts as to why I'm not able to get this to write the date/time in column C in the row that I've updated?

Clark Lind

unread,
Jun 23, 2022, 7:42:34 AM6/23/22
to Google Apps Script Community
I don't think you need to specify the sheet or spreadsheet since you already have an event object with that information. 
If you are always editing just one column (say col B), you should be able to get away with something like this:

e.range.offset(0, 1).setValue( new Date() ).

To add in some safety, you could also add a check to ensure proper sheet and column are what you intend:

function onEdit(e) {
  if ( (e.source.getActiveSheet().getName() ===  'Sandbox') ) && (e.range.getColumn() === '2.0') ) {   //assuming Col B is your intended edit Col
      e.range.offset(0, 1).setValue( new Date() ).
Reply all
Reply to author
Forward
0 new messages