onEdit help

Skip to first unread message

Jun 22, 2022, 1:51:41 PMJun 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

Jun 23, 2022, 7:42:34 AMJun 23
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
0 new messages