Paste after last row

I'm trying to paste values from an other tab that is from a IMPORTRANGE, but when I try to paste the value, it is not possible because the value from variable afterLastRow transform it in a Boolean and the object copyValuesToRange needs a integer.

Tks by help

function copiaValoresImportrange() {

  //VARIÁVEL QUE ATRIBUI O SCRIPT PARA A PLANILHA
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  //VARIÁVEIS QUE ADQUIREM OS NOMES DAS ABAS DE ORIGEM E DESTINO
  var sheetOrigem  = ss.getSheetByName('ORIGEM');
  var sheetDestino = ss.getSheetByName('DESTINO');
  var afterLastRow = Number(sheetDestino.getLastRow()) + 1;

  //VARIÁVEL QUE VERIFICA AS EXTENSÕES DA PLANILHA DE ORIGEM
  var local = sheetOrigem.getRange(1, 1, afterLastRow, sheetOrigem.getLastColumn());

  //FUNÇÃO QUE COPIA OS DADOS DA PLANILHA DE ORIGEN NA PLANILHA DE DESTINO
  local.copyValuesToRange(sheetDestino, 1, sheetOrigem.getLastColumn(), 1, afterLastRow);

 }

Upvotes: 1

Views: 657

Answers (1)

Brian
Brian

Reputation: 4344

Two suggestions:

You don't need var afterLastRow = Number(sheetDestino.getLastRow()) + 1;. You can call sheetDestino.getLastRow() + 1 and get the correct integer.

Second, copyValuesToRange() needs the sheet id, not the name, according to the documentation.

Upvotes: 1

Related Questions