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

155
Vistas
Javascript: Copy specified Col through last col and paste down to last row

I'm extremely green to javascript and have pieced together what I need through searching online and watching videos. I need to set multiple columns in row4, starting from col 18 through to lastcolumn, as the active cells to copy and then pasteformulas down to the last row (if necessary, based on col 4's data). Code I have below activates (selects) all data from col 18 through last column (as intended) but also through last row (unintended). Anyone know how to correct this?

    function CopyFormulasDown() {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var sRA4 = ss.getRange(4,1); //First copy is A4 ..this one works as intended
  var lr = ss.getLastRow();
  var lc = ss.getLastColumn();
  var sRR4lc = ss.getRange('R4:'+ lc +'4'); //Trying to select R4 through last col within row4; also tried (4,18+':'+lc), but throws an error: Exception: Cannot convert '18:37' to int.
  var fillDownRangeA4 = ss.getRange(4,1,lr);
  var fillDownRangeR4lc = ss.getRange(4,18,lr,lc);
  
   // sRA4.activate(); //range cell A4 is copied
    //sRA4.copyTo(fillDownRangeA4);  //copied cell pastes formula down to last row ..WORKS!
    sRR4lc.activate(); //ROW4 COL18 is selected through to last col as intended, but also selects down to last row.... problem is I didn't tell it to select past row 4... not sure how to correct this
   // sRR4lc.copyTo(fillDownRangeR4lc); //commented out for now until I can get just row 4 from col 18 through last col copy to work
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Omgoodness. After typing out the question and posting, I thought of adding the lc to the numofcolumns place instead. Below is the working code for anyone who's interested:

  function CopyFormulasDown() {
    var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    var sRA4 = ss.getRange(4,1); //copy A4
    var lr = ss.getLastRow();
    var lc = ss.getLastColumn();
    var sRR4lc = ss.getRange(4,18,1,lc); //select R4 through last col within row4
    var fillDownRangeA4 = ss.getRange(4,1,lr);
    var fillDownRangeR4lc = ss.getRange(4,18,lr,lc);
    
      sRA4.activate(); //range cell A4 is copied
      sRA4.copyTo(fillDownRangeA4);  //copied cell pastes formula down to last row ..WORKS!
      sRR4lc.activate(); //ROW4 COL18 is selected through to last col
      sRR4lc.copyTo(fillDownRangeR4lc);
};
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