Advertisement
mentoly

Clone Sheet to Another Sheet

Dec 11th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copy data from Google Sheet A to Google Sheet B
  2.  
  3. function cloneImportData(ssA, ssB) {
  4.  
  5. // source doc
  6. var sss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1t93TiemQfXWkMhOxKtCyjkzPkE6WF-ce1CnQgVDfJfc/edit#gid=1312573476')
  7.  
  8. // source sheet
  9. var ss = sss.getSheetByName('ImportData');
  10.  
  11. // Get full range of data
  12. var SRange = ss.getDataRange();
  13.  
  14. // get A1 notation identifying the range
  15. var A1Range = SRange.getA1Notation();
  16.  
  17. // get the data values in range// Copy data from Google Sheet A to Google Sheet B
  18.  
  19. function cloneImportData(ssA, ssB) {
  20.  
  21. // source doc
  22. var sss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1t93TiemQfXWkMhOxKtCyjkzPkE6WF-ce1CnQgVDfJfc/edit#gid=1312573476')
  23.  
  24. // source sheet
  25. var ss = sss.getSheetByName('ImportData');
  26.  
  27. // Get full range of data
  28. var SRange = ss.getDataRange();
  29.  
  30. // get A1 notation identifying the range
  31. var A1Range = SRange.getA1Notation();
  32.  
  33. // get the data values in range
  34. var SData = SRange.getValues();
  35.  
  36. // target spreadsheet
  37. var tss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1t93TiemQfXWkMhOxKtCyjkzPkE6WF-ce1CnQgVDfJfc/edit#gid=1312573476')
  38.  
  39. // target sheet
  40. var ts = tss.getSheetByName('CachedData');
  41.  
  42. // Clear the Google Sheet before copy
  43. ts.clear({contentsOnly: true});
  44.  
  45. // set the target range to the values of the source data
  46. ts.getRange(A1Range).setValues(SData);
  47.  
  48. };
  49. var SData = SRange.getValues();
  50.  
  51. // target spreadsheet
  52. var tss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1t93TiemQfXWkMhOxKtCyjkzPkE6WF-ce1CnQgVDfJfc/edit#gid=1312573476')
  53.  
  54. // target sheet
  55. var ts = tss.getSheetByName('CachedData');
  56.  
  57. // Clear the Google Sheet before copy
  58. ts.clear({contentsOnly: true});
  59.  
  60. // set the target range to the values of the source data
  61. ts.getRange(A1Range).setValues(SData);
  62.  
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement