Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda