Home > Net >  Google Script: Copy row from one sheet to another depending on value
Google Script: Copy row from one sheet to another depending on value

Time:02-23

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.

CodePudding user response:

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