Advertisement
mentoly

Archive Data to Another Sheet

Dec 11th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function MasterSheetBackup() {
  2.  
  3.  var sss = SpreadsheetApp.openById('16F8fstwI61rOgl2iNnlrwsyQOcqnSJ2Nj8zXJJFJLAk'); //replace with source ID
  4.  var ss = sss.getSheetByName('MasterSheet'); //replace with source Sheet tab name
  5.  var range = sss.getRange('A:CW'); //assign the range you want to copy
  6.  var data = range.getValues();
  7.  
  8.  var tss = SpreadsheetApp.openById('1yQGyrwDWC0Xp3fUDl0heD5IEz5IumpjilrZnzlLN2jc'); //replace with destination ID
  9.  var ts = tss.getSheetByName('MasterSheetBackup'); //replace with destination Sheet tab name
  10.  ts.getRange(1, 1, data.length, data[0].length).setValues(data);
  11.  
  12. }
  13.  
  14.  
  15.  
  16. function masterSheetBackup(ssA, ssB) {
  17.  
  18.   // source doc
  19.   var sss = SpreadsheetApp.openById('1M7-l6gJdtoDVD7v9NBa1thESyTbclRhiuvgYTnjpNxI');
  20.  
  21.   // source sheet
  22.   var ss = sss.getSheetByName('masterSheet');
  23.  
  24.   // Get full range of data
  25.   var SRange = ss.getDataRange();
  26.  
  27.   // get A1 notation identifying the range
  28.   var A1Range = SRange.getA1Notation();
  29.  
  30.   // get the data values in range
  31.   var SData = SRange.getValues();
  32.  
  33.   // target spreadsheet
  34.   var tss = SpreadsheetApp.openById('1UHPtXJj2-N-STEzh65ZlXbeAcCoxuVLIzCvgh2qcalA');
  35.  
  36.   // target sheet
  37.   var ts = tss.getSheetByName('masterSheetBackup');
  38.  
  39.   // Clear the Google Sheet before copy
  40.   ts.clear({contentsOnly: true});
  41.  
  42.   // set the target range to the values of the source data
  43.   ts.getRange(A1Range).setValues(SData);
  44.  
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement