I am trying to loop over a specific column and look for values. When a cell value = 0, I want to copy other columns in that row to another sheet.
function selectCopy() {
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Intake');
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Service Pending');
var sheet3 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Service Complete');
var sheet4 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('To Reissue');
var sheet5 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Discovery');
var lastRow1 = sheet1.getLastRow();
var lastRow2 = sheet2.getLastRow();
var lastRow3 = sheet3.getLastRow();
var lastRow4 = sheet4.getLastRow();
var lastRow5 = sheet5.getLastRow();
var startRow = 2;
var range = sheet2.getRange(2,1, lastRow1-startRow+1,1);
var numRows2 = range.getNumRows();
var case_number_values = range.getValues();
range = sheet2.getRange(2,2, lastRow1-startRow+1,1);
var name_values = range.getValues();
var range = sheet2.getRange(2,6, lastRow2-startRow+1,1);
var days_left_values = range.getValues();
var selection = sheet2.getDataRange();
range = sheet2.getRange(2,7, lastRow2-startRow+1,1);
var sent_to_server_values = range.getValues();
range = sheet2.getRange(2, 4, lastRow2-startRow+1,1);
var issue_date_values = range.getValues();
range = sheet2.getRange(2, 5, lastRow2-startRow+1,1);
var service_deadline_values = range.getValues();
range = sheet2.getRange(2,8, lastRow2-startRow+1,1);
var service_date_values = range.getValues();
for (var i=0; i<= numRows2-1; i++){
var days_left = days_left_values[i][0];
if (days_left === 0){
var case_number = case_number_values[i][0];
var name = plaintiff_name_values[i][0];
var service_date = service_date_values[i][0];
var issue_date = issue_date_values[i][0]
var service_deadline = service_deadline_values[i][0];
var sent_to_server = sent_to_server_values[i][0];
sheet4.getRange(lastRow4+1,1).setValue(case_number);
sheet4.getRange(lastRow4+1,2).setValue(name);
sheet4.getRange(lastRow4+1,4).setValue(service_deadline);
}
}
}
It is sort of working but it is only copying the last row that has a cell = 0. So If I have three rows in column 6, whos value = 0, I want to copy all three rows, this code is only copying the last row.