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

149
Vistas
Add Row based on cell value, Below the last data in column A

I just need some help, I got this code in youtube that adds rows to the specified sheet, but the code that I got is just adding rows after row 2 and just keeps on adding it non-stop.

here is the code:

function insertRow() {
  let spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  let sheetToAdd = spreadSheet.getSheetByName('test sheet');

  let lastRowEdit = sheetToAdd.getLastRow();

  for(var i = 2; i <= lastRowEdit; i++)
  {
    sheetToAdd.insertRowAfter(i);
  }
}

What I want is to add row below the last row with data in column A. And the number of the rows to be added is based on cell B2 in another sheet

sample spreadsheet: https://docs.google.com/spreadsheets/d/1sX6wS0ZPeLC1u0nbU2m8jeZ3dMVEXhkFPR_Ply27Z18/edit#gid=746083055

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

0

This code may solve your issue: Prerequisite: A google spreadsheet with one sheet called Info containing the amount of rows to add in cell 'B2'. A sheet called 'add here' which will be filled by the script below.

By changing it according to your sheet names you can basically copy pasta it.

Comments for help!

function insertRow() {
  let spreadSheet = SpreadsheetApp.getActiveSpreadsheet(); // activates the opened document
  let sheetToAdd = spreadSheet.getSheetByName('add here'); // selects the sheet at the bottom of the SpreadSheet (SpreadSheet is a collection of Sheets (!))

  let rowsToAdd = spreadSheet.getSheetByName('Info').getRange(2,2).getValue(); // get cell B2

  let lastRow = sheetToAdd.getLastRow() + 1; // you want to add after the last row with data
  
  for(var i = 0; i <= rowsToAdd; i++){
    sheetToAdd.getRange(lastRow+i, 1).setValue(i); // get the cell at lastRow+counter and column 1; set the value as wished
  }
}

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