Guest User

md982jdib2d

a guest
Jan 2nd, 2016
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function checkIfNewRow() {
  3.  
  4.  var ss = SpreadsheetApp.getActiveSpreadsheet();
  5.  var sheetLatest = ss.getSheets()[2];
  6.  var sheetNew = ss.getSheets()[0];
  7.  var latestNew = sheetNew.getRange(sheetNew.getLastRow(), 1).getValue(); // date
  8.  var lastestProcessed = sheetLatest.getRange(sheetLatest.getLastRow(), 1).getValue(); // date
  9.  
  10.   if(latestNew != lastestProcessed) {
  11.     // Process it!!
  12.     addToFinalSheet();
  13.    
  14.     // Append to latests processed sheet
  15.     sheetLatest.appendRow([latestNew]);
  16.    
  17.   } else {
  18.     // do nothing, as there is nothing new
  19.   }
  20. }
  21.  
  22.  
  23.  
  24. function addToFinalSheet() {
  25.  
  26.  var ss = SpreadsheetApp.getActiveSpreadsheet();
  27.  var sheet = ss.getSheets()[0];
  28.  
  29.  var lastRowInt = sheet.getLastRow();
  30.  
  31.  var dateTimeStartedSleeping = sheet.getRange(lastRowInt, 1);
  32.  var finalDate = dateTimeStartedSleeping.getValue().replace('at ', ', ');
  33.  
  34.  var hoursSlept = sheet.getRange(lastRowInt, 2);  
  35.  var finalHours = 'for ' + hoursSlept.getValue().replace('h', ' hours').replace('m', ' minutes');
  36.  var sheet2 = ss.getSheets()[1];
  37.  
  38.  // Appends a new row with 3 columns to the bottom of the
  39.  // spreadsheet containing the values in the array
  40.  sheet2.appendRow([finalDate, finalHours]);
  41.  
  42. }
RAW Paste Data