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

354
Visualizações
Google Script: Copy row from one sheet to another depending on value

While ive seen similar questions ive not seen this specific one if im not mistaken.

So, i need to read all the info in a certain column (in this case it would be AF, regardless i havent been using that spreadsheet to try what ive been doing out) and then check whether a cell in that column has the value(or string, sorry new to Google Script) "Finalized" then copy the entire row that corresponds to that cell to a secondary sheet which would store all the finished cases and stuff.

ive been trying to find something thru google but its always how to copy the entire sheet and thats not useful i think, also what ive done rn copies the cells regardless of what the value is on that cell+column

function copyIf() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getSheetByName("Stuff"); 
  var destination = ss.getSheetByName("Terminados");
  var condition = source.getRange('D2:D2000').getValue();
  if (condition == "Terminado") {  
    source.getRange('A2').copyTo(destination.getRange('A2'));
    source.getRange('A3').copyTo(destination.getRange('A3'));
  } 
}

i am thinking i should probably implement some sort of for or while loop cause i want this to run constantly so whenever someone changes the status of a certain cell to Terminado to copy that row to the secondary sheet.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this

function copyIf() {
  var feuille = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Stuff");
  var archive = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Terminados");
  if (feuille.getLastRow()==1){
    SpreadsheetApp.getActive().toast('No data!', 'End of script 🗃️')
    return
  }
  var data = feuille.getRange(2,1,feuille.getLastRow()-1,feuille.getLastColumn()).getValues()
  var archiveData = []
  var lignes = []
  var ligne = 1
  var col = 31 // AF
  try {
    data.forEach(function (row) {
      if (row[col]=="Terminado") {
        archiveData.push(row)
        lignes.push(ligne)
      }
    })
    archive.getRange(archive.getLastRow() + 1, 1, archiveData.length, archiveData[0].length).setValues(archiveData)
    // lignes.reverse().forEach(x => feuille.deleteRow(x));
    SpreadsheetApp.getActive().toast('Rows '+lignes.flat()+' hab been archived !', 'End of script 🗃️')
  } catch (e) {
    SpreadsheetApp.getActive().toast('No data to be archived!', 'End of script 🗃️')
  }
}

If you want to delete rows after process, remove // before lignes.reverse().forEach(x => feuille.deleteRow(x));

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