0

This question already has an answer here:

In a particular cell of a column, I would like to have a timestamp of the last date any cell of that column was modified. Specifically: G31 would show a date of last modification on any cell of the G column.

My question is quite similar to this one, but I can't seem to apply it to my situation :
Auto-updating column in Google Spreadsheet showing last modify date

I have tried this :

function onEdit() 
{ var DEVIS_COMPLET_2018 = "MySheet"; 
var s = SpreadsheetApp.getActiveSheet(); 
if (s.getName() !== DEVIS_COMPLET_2018) return; 
var r = s.getActiveCell(); 
if( r.getColumn() != G ) { //checks the column 
var row = r.getRow(); 
var time = new Date(); 
time = Utilities.formatDate(time, "GMT-08:00", "MM/DD/yy");
SpreadsheetApp.getActiveSheet().getRange('G31').setValue(time); }; }; 

I don't get any error message but nothing happens.

I have tried enclosing G, still no luck :

function onEdit() {
var DEVIS_COMPLET_2018 = "MySheet";
var s = SpreadsheetApp.getActiveSheet();
if (s.getName() !== DEVIS_COMPLET_2018) return;
var r = s.getActiveCell();
if( r.getColumn() != "G" ) { //checks the column
var row = r.getRow();
var time = new Date();
time = Utilities.formatDate(time, "GMT-08:00", "MM/DD/YY");
SpreadsheetApp.getActiveSheet().getRange("G31").setValue(time); }; };

marked as duplicate by Rubén, ale, serenesat, Alex, jonsca Jul 6 '18 at 22:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Welcome. Where do you get stuck on applying the answer to the referred question? – Rubén Jul 4 '18 at 21:41
  • The trouble I have is I want a timsestamp that applies only to a specific column and I want the timestamp to show in only one cell. I don't know if I'm being super helpful... – Fanny Bissonnette Jul 5 '18 at 15:14
  • That is what you want to achieve not where get stuck. Add your adaptation of the code of the referred question and if you get an error message add it textually. – Rubén Jul 5 '18 at 15:22
  • Comments are intended for asking clarifications, give suggestions to improve a post. All the important information should be included on the question/answer. Please edit your question to add the code. – Rubén Jul 5 '18 at 15:44
  • One of the problems is r.getColumn() != G As G is not quote enclosed it's considered a variable name but it's not defined. – Rubén Jul 5 '18 at 16:17
0

Try

function onEdit(e) {
var sh = e.range.getSheet(); //sheet    
if (sh.getName() !="DEVIS_COMPLET_2018" || e.range.columnStart != 7 ) { return; }
sh.getRange("G31").setValue(new Date());
}
  • The time zone if off but other than that it works like a charm!! Thank you! – Fanny Bissonnette Jul 5 '18 at 20:19
0

The script apparently does nothing because the condition (r.getColumn() != G)

  • getColumn() returns an integer
  • G, as it's not quote enclosed it's considered a variable name. As it's not declared previously it returns undefined.

Another possible problem is on time = Utilities.formatDate(time, "GMT-08:00", "MM/DD/yy"); The problem is that DD will return the day on the year instead the day on the month.

  • Thank you, I tried enclosing G but still no luck. – Fanny Bissonnette Jul 5 '18 at 17:02
  • @FannyBissonnette you missed the part that getColumn() returns an integer. For a quick fix, instead of "G" put 7, as was shown on the answer by user0 but it will be much better that you try to understand how Apps Script works instead of just copy pasting code that you find anywhere. – Rubén Jul 5 '18 at 17:11
  • Consider to take a basic JavaScript course. It's very likely that doing that will save you a lot of headaches and time. – Rubén Jul 5 '18 at 17:18
0
function onEdit() {
  var sheetName = "Sheet1";
  var s = SpreadsheetApp.getActiveSheet();
  if (s.getName() !== sheetName) return;
  var r = s.getActiveCell();
  if( r.getColumn() != 7 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-08:00", "MM/dd/yy");
    SpreadsheetApp.getActiveSheet().getRange('G31').setValue(time);
  };
 };

Not the answer you're looking for? Browse other questions tagged or ask your own question.