On edit timestamp

37 views
Skip to first unread message

Rishi

unread,
Sep 28, 2022, 4:02:06 AM9/28/22
to Google Apps Script Community
Hi all,

I am beginner in script and learning.

I have file, I want to time stamp when I edit Column starting from "A2:A"  the timestamp in column no. 4 and remove timestamp when user remove value.

I have script but it is only working all column not in particular column. Pls. help




Script in file

function onEdit(e) {

  var sheet = SpreadsheetApp.getActive().getActiveSheet();
  var changes = e.range.getValues();
 
 
  // +1 because of header row
  var lastRow = e.range.getLastRow() + 1;
  var date = new Date();
  var dateOfChange = date 
  var timeColumn = 4

  //sheet.getDataRange().getLastColumn()
  for (var i = 0i < changes.lengthi++) {
    var row = (lastRow - changes.length) + i;
    var timeCell = sheet.getRange(rowtimeColumn);

    //this is quick and dirty but you will probably want to add more advanced data validation
    var validator = 0
    changes[i].forEach(function(x) {x.toString().length > 0 ? validator++ : null;})

    if (validator > 0 && e.range.getLastColumn() < timeColumn) {
      timeCell.setValue(dateOfChange);
    } else {
      timeCell.clear()
    }
  }
}


thanks and regards

Rishi

unread,
Oct 6, 2022, 6:35:10 AM10/6/22
to Google Apps Script Community

can anyone help on this.

Jon Couch

unread,
Oct 6, 2022, 7:40:32 AM10/6/22
to google-apps-sc...@googlegroups.com
Rishi, I'm not that proficient myself, but taking just a quick look at your code, I think you might need a qualifier before you execute the function. Have you tried checking the active cell to ensure you are in column 1 before you run the script? Since you're limited to one onEdit function, I normally check the active cell and then execute the desired code for that cell or range of cells. I hope this helps.
Jon


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/df3a8d76-82ef-4433-8a62-850f8fb5ccf1n%40googlegroups.com.

Rishi Raj

unread,
Oct 10, 2022, 6:01:11 AM10/10/22
to Jon Couch, google-apps-sc...@googlegroups.com
Dear Mr. Couch,

Thanks for the reply, I will check.



You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/d8_Q1kSZDOo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CADjEj87%2BCi5wMkAJysJExXEPggF5Tqj%2BC4KNDsHGBUJ7VLw4tw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages