I know this topic was covered several years ago here: Copy a complete list on one spreadsheet to append on the bottom of another spreadsheet
Here is the script:
function transferList() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("RFP List");
var sourceData = sourceSheet.getDataRange().getValues();
sourceData.splice(0,1); // Remove header
var targetSS = SpreadsheetApp.openById("0ABCD").getSheetByName("RFPData");
var targetRangeTop = targetSS.getLastRow(); // Get # rows currently in target
targetSS.getRange(targetRangeTop 1,1,sourceData.length,sourceData[0].length).setValues(sourceData);
}
But I'm trying to use this now and the last line of the script is not working for me. I get an error message saying "Exception: The parameters (String,number,number,number) don't match the method signature for SpreadsheetApp.Spreadsheet.getRange."
I'm a total newbie and would be so grateful for help figuring out how to make this work. Also to make things simpler, I don't need to remove the header like they did using splice.
CodePudding user response:
Try it this way:
function transferList() {
const ss = SpreadsheetApp.getActive();
const sh1 = ss.getSheetByName("RFP List");
const [hA,...vs1] = sh1.getDataRange().getValues();//array literal assignment the header array is still available for later use
const tss = SpreadsheetApp.openById("0ABCD");
const tsh = tss.getSheetByName("RFPData");
tsh.getRange(tsh.getLastRow() 1,1,vs1.length,vs1[0].length).setValues(vs1);
}