Enter the current date in the cell when changing another cell

I have a Google spreadsheet that I use to track the status of configuration information requested for the application from the client. For example. The text to enable the button. I have a column with the inscription โ€œStatusโ€ at the top and cells with data validation โ€œList out of rangeโ€ in the lines below. The used range has "With a client", "With me", "Completed". I also have a column on the right, which I use to add a date for the last time when the status changes. I would like the date to be automatically changed until today when I change status. I believe this can be done with a script, but I have never used it before.

+7
google-spreadsheet google-apps-script
source share
3 answers

Another answer started with a good idea, but, unfortunately, the proposed code does not work, because it has many basic errors (obviously, it was not tested ...)

So here is a version that just works:

function onEdit(e) { var sheet = e.source.getActiveSheet(); var activeCell = sheet.getActiveCell(); var col = activeCell.getColumn(); var row = activeCell.getRow(); if (col == 2 ) { // assuming status is in column 2, adapt if needed sheet.getRange(row, col+1).setValue(new Date()).setNumberFormat('MMM dd yyyy');// change the display format to your preference here } } 
+13
source share
  column 'Status' column 'date' row 'List from Range' 12-08-20014 row 'Data Validation' ----------- 

range {'With client', 'With Me', 'Completed'}

ok, if you open your script editor and add the code below, replace the BOLD TERMS with the appropriate values. onEdit () should not have a trigger, since it is a "special" function if you do not share the sheet and do not need to run it with developer privileges.

 onEdit() { var sheet = e.source.getActiveSheet(); var col = activecell.getColumn(); // numeric value of column, ColA = 1 var row = activecell.getRow(); // numeric value of row if (col == PUT IN THE NUMBER OF YOUR COLUMN 'Status') { sheet.getRange(row, col+1) = Date(); } 
+1
source share
 function onEdit(e) { var sheet = e.source.getActiveSheet(); var activeCell = sheet.getActiveCell(); var col = activeCell.getColumn(); var row = activeCell.getRow(); if (col == 2) { sheet.getRange(row, 1).setValue(new Date()).setNumberFormat('dd/MM/yyyy H:m:s'); } } 
+1
source share

All Articles