0

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); }; };
6
  • Welcome. Where do you get stuck on applying the answer to the referred question? Commented Jul 4, 2018 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... Commented Jul 5, 2018 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. Commented Jul 5, 2018 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. Commented Jul 5, 2018 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. Commented Jul 5, 2018 at 16:17

3 Answers 3

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());
}
1
  • The time zone if off but other than that it works like a charm!! Thank you! Commented Jul 5, 2018 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.

3
  • Thank you, I tried enclosing G but still no luck. Commented Jul 5, 2018 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. Commented Jul 5, 2018 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. Commented Jul 5, 2018 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);
  };
 };
0

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