Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

353
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!