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

363
Vistas
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 Respuestas
Responde la pregunta

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 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