I have a script for Google Sheets that when I click a button, I want it to copy all rows that meet that condition onto a new tab. Currently it only copies 1 row when clicked and won’t copy each one that meets the condition. Basically I go through column 13 and mark a bunch of rows as true with a checkbox, and after doing so I want to double check them all then click a button to automatically send them all to another tab. I can’t seem to figure out why the button only sends 1 row at a time when clicked.
function moveRows() {
var mainSheet = "Temp Rack";
var sheetToMoveTheRow = "Dead Temp Rack";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = SpreadsheetApp.getActiveRange();
if(sheet.getName() == "Temp Rack" && range.getColumn() == 13 && range.getValue() == true) {
var row = range.getRow();
var numColumns = sheet.getLastColumn();
var targetSheet = ss.getSheetByName("Dead Temp Rack");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sheet.getRange(row, 1, 1, numColumns).moveTo(target);
sheet.deleteRow(row);
} else if(sheet.getName() == "Dead Temp Rack" && range.getColumn() == 13 && range.getValue() == false) {
var row = range.getRow();
var numColumns = sheet.getLastColumn();
var targetSheet = ss.getSheetByName("Temp Rack");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sheet.getRange(row, 1, 1, numColumns).moveTo(target);
sheet.deleteRow(row);
}
}
I tried the above code, I expected it to move them all, it only moves 1 row.
Onion Of Green is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.