Advertisement
Guest User

Untitled

a guest
Oct 4th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // working timestamp code
  2. // function onEdit(e) {
  3. //   var ss = e.source;
  4. //   var timestamps_sheet = ss.getSheetByName('timestamp_reference');
  5. //   const row = e.range.getRow();
  6. //   if (row > 1) {
  7. //     if (e.source.getActiveSheet().getName() === "sports_team") {
  8. //       const currentDate = new Date();
  9. //       timestamps_sheet.getRange(row, 1).setValue(currentDate);
  10. //     }
  11. //   }
  12. // }
  13.  
  14. // working code to find row # where cell = "timestamp"
  15. // function onEdit(e){
  16. //    var ss = SpreadsheetApp.getActiveSpreadsheet();
  17. //    var thisSheet = ss.getActiveSheet();
  18. //    var tf = thisSheet.createTextFinder("timestamp");
  19. //    var thisRow = tf.findNext().getRow();
  20. //   //  var thisCol = tf.findNext().getColumn();
  21. //    Browser.msgBox(thisRow, Browser.Buttons.OK_CANCEL);
  22. //    return thisRow;
  23. // }
  24.  
  25. // working code to find column # ONLY if "timestamp" is in Row 1. Unable to figure how to find column # after Row 1
  26. // function onEdit(e) {
  27. //   var headers = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sports_team').getDataRange().getValues().shift();
  28. //   var colindex = headers.indexOf("timestamp");
  29. //   Browser.msgBox(colindex+1, Browser.Buttons.OK_CANCEL);
  30. //   // return colindex+1;
  31. // }
  32.  
  33.  
  34. function onEdit(e){
  35.   var ss = SpreadsheetApp.getActiveSpreadsheet();
  36.   var thisSheet = ss.getActiveSheet();
  37.   var tf = thisSheet.createTextFinder("timestamp");
  38.  
  39.   // This finds Row # where cell = "timestamp"
  40.   var thisRow = tf.findNext().getRow();
  41.   // This is supposed to find Col # where it = "timestamp" but I'm having issues
  42.   var thisCol = tf.findNext().getColumn();
  43.  
  44.  
  45.   var ss = e.source;
  46.   var main_sheet = ss.getSheetByName('sports_team');
  47.   const row = e.range.getRow();
  48.   if (e.source.getActiveSheet().getName() === "sports_team") {
  49.     const currentDate = new Date();
  50.     main_sheet.getRange(thisRow, thisCol).setValue(currentDate);
  51.   }
  52. }
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement