0
votes

I've been trying to copy a range from a spreadsheet and paste into another spreadsheet on Google Docs. Whenever I run the script I get Target range and source range must be on the same spreadsheet

function myFunction() {
var ss1 = SpreadsheetApp.getActiveSpreadsheet ();
var ss2 = SpreadsheetApp.openById("1wIVQA-QhgSvTpmrIl4R6Gwhh1pMKcVKEcdFPa8_KTXw");
var source = ss2.getRange ("Moz!D2:J2");
var destiny = ss1.getRange("Sheet1!A2:B2");
source.copyTo (destiny, {contentsOnly: true});
source.clear ();
}

Apparently is possible but I couldn't work it out yet. Source: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app

1
Apparently Google changed how copyTo() works stackoverflow.com/questions/4509336/…. Does anyone know a workaround?Felipe

1 Answers

1
votes

Try:

function myFunction() {
  var ss1 = SpreadsheetApp.getActiveSpreadsheet ();
  var ss2 = SpreadsheetApp.openById("1wIVQA-QhgSvTpmrIl4R6Gwhh1pMKcVKEcdFPa8_KTXw");
  var source = ss2.getSheetByName("Moz").getRange("D2:E2");
  var sourceValues = source.getValues();
  var destiny = ss1.getSheetByName("Sheet1").getRange("A2:B2");
  destiny.setValues(sourceValues);
  source.clear();
}