0
votes

My manager and I are stuck!

What we are trying to do is pull all of the data from one google sheet to the first tab on another google sheet using google App Script. They are located in 2 separate folders as well.

We don't want to use =importrange() basic because it doesn't actively update the sheet! We are trying to automate our systems!

we tried using this and it was a no go.

function CopyRange() {
 var sss = SpreadsheetApp.openById('1vuqVDFLYc0pee0qITCQoL6ZXAOlzVl5Efg88F8mA39I'); //replace with source ID
 var ss = sss.getSheetByName('Bob Swope - Flow'); //replace with source Sheet tab name
 var range = ss.getRange('A2:AL1000'); //assign the range you want to copy
 var data = range.getValues();
 var tss = SpreadsheetApp.openById('17SZH2yKWuD1fonf-hOV1bpUumuOf5S24NI_V2Q0ITWo'); //replace with destination ID
 var ts = tss.getSheetByName('input'); //replace with destination Sheet tab name

}
1
What is your current issue of your script? - Tanaike

1 Answers

1
votes
function movingData() {
  var sss=SpreadsheetApp.getActive();//assuming this script is contained within this spreadsheet other you might wish to use openById();
  var dss=SpreadsheetApp.openById('SSID');//open destination spreadsheeet by id
  var dsh=dss.getSheets()[0];//first sheet on the left
  var shts=sss.getSheets();//array of all sheets
  //loop through all sheets getting data and appending to dsh
  shts.forEach(function(sh,i){
    var v=sh.getDataRange().getValues();
    dsh.getRange(dsh.getLastRow()+1,1,v.length,v[0].length).setValues(v);
  });
}

Class SpreadsheetApp

Assuming that you might wish to exclude some sheets from the source. Then something like this might be useful.

function movingData() {
  var exclA['Sheetnames','To','Exlude']
  var sss=SpreadsheetApp.getActive();
  var dss=SpreadsheetApp.openById('SSID')
  var dsh=dss.getSheets()[0];
  var shts=sss.getSheets();
  shts.forEach(function(sh,i){
    if(exclA.indexOf(sh.getName())==-1) {
      var v=sh.getDataRange().getValues();
      dsh.getRange(dsh.getLastRow()+1,1,v.length,v[0].length).setValues(v);
    }
  });
}