Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
How to Copy a data range from one sheet to another sheet using Google Sheet Script

Disclaimer: I am just new in coding and I just want to automate things up in my work.

I want to copy a data from 'Data Entry' sheet to another sheet specified by the cell in 'Data Entry' sheet.

here is the code that I am using:

function DataEntry() {
  let spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  let sourceSheet = spreadSheet.getSheetByName('Data Entry');

  let sourceRange = sourceSheet.getDataRange();
  let sourceValues = sourceRange.getValues();

  let rowCount = sourceValues.length();
  let columnCount = sourceValues[0].length();

  let targetSheet = spreadSheet.getSheetByName('6');
  let targetRange = targetSheet.getRange(2,1,rowCount,columnCount);

  targetRange.setValues(sourceValues);
}

In the source sheet, I want to copy the data starting from row 3, column L. (the number of rows varies every data batch)

Then in the target sheet, which will be specified by a cell in source sheet (cell T2). The pasting should start at row 2, column A.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

function DataEntry() {
  let spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  let sourceSheet = spreadSheet.getSheetByName('Data Entry');

  let sourceRange = sourceSheet.getDataRange();
  let sourceValues = sourceRange.getValues();
  let sheetName = sourceValues[1][19];
  sourceValues = sourceValues.slice(2).map(row => row.slice(11));

  let rowCount = sourceValues.length;
  let columnCount = sourceValues[0].length;

  let targetSheet = spreadSheet.getSheetByName(sheetName);
  let targetRange = targetSheet.getRange(2,1,rowCount,columnCount);

  targetRange.setValues(sourceValues);
}

Explanation:

  • Since getValues() returns a 2D array, in order to get the value from a certain cell you just have to use the appropriate array indexes to access the desired element (in this case, 1 and 19, corresponding to T2).
  • Use map and slice to retrieve a subset of the range values. You could also retrieve the corresponding range directly (e.g. sourceSheet.getRange("L3:L").getValues().flat().filter(String)), but in this way you are minimizing the amount of calls to the spreasdheet service, which is a good practice.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda