SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function main(){
  2.   //Master Sheet
  3.   var sprsheet = SpreadsheetApp.getActiveSpreadsheet();
  4.   var master_sheet = sprsheet.getSheetByName("ENTRATE MAIN");
  5.   var master_range = master_sheet.getRange("AJ2:J50");
  6.   //Second Sheet
  7.   var sheetName = master_sheet.getRange("Z1").getValue();
  8.   var second_sheet = sprsheet.getSheetByName(sheetName);
  9.   var lastrow = second_sheet.getLastRow();
  10.  
  11.   var master_data = master_range.getValues();
  12.  
  13.   if (lastrow > 50){ //This is in case your second sheet has less than 50 rows before copying the data
  14.     //We have to check the previous 49 rows in case the data is already there
  15.     var second_range = second_sheet.getRange("AJ"+(lastrow-49)+":J"+(lastrow));
  16.     var second_data = second_range.getValues();
  17.  
  18.     if (!isCopied(master_data, second_data)){
  19.       //Data is not there so we copy it in the next 49 rows
  20.       second_range = second_sheet.getRange("AJ"+(lastrow+1)+":J"+(lastrow+49));
  21.       second_range.setValues(master_data);
  22.  
  23.     }
  24.   } else {
  25.     //The second sheet has less than 50 rows so the data is obviously not there
  26.     var second_range = second_sheet.getRange("AJ"+(lastrow+1)+":J"+(lastrow+49));
  27.     second_range.setValues(master_data);
  28.  
  29.   }
  30. }
  31.  
  32. function isCopied(master_data, second_data){
  33.   for (i in master_data){
  34.     for (j in master_data[i]){
  35.       if (master_data[i][j] != second_data[i][j]){
  36.         return false;
  37.       }
  38.     }
  39.  
  40.   }
  41.   return true;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top