In Google Sheets, I have been trying to copy data from Sheet "Main" to Sheets (Completed, Pending, Hold) based on selection from dropdown in column 6 named (Status) in Main Sheet.
Column 6 DropDown List (Completed, Pending, Main)
Once a specific record has been changed it copies the record to its specific sheet without deleting the record from the Main sheet.
So far I have got this from elsewhere, however this does not seem to work, can someone please help.
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
If(s.getName() == "Main" && r.getColumn() == 6 && r.getValue() == "Completed"); {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() +1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
If(s.getName() == "Main" && r.getColumn() == 6 && r.getValue() == "Pending"); {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Pending");
var target = targetSheet.getRange(targetSheet.getLastRow() +1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
If(s.getName() == "Main" && r.getColumn() == 6 && r.getValue() == "Hold"); {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Hold");
var target = targetSheet.getRange(targetSheet.getLastRow() +1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
2
Answers
In the “Active” tab, cell
C3
put:And in the “Active” tab, cell
O3
put:A checked checkbox is interpreted as “TRUE” so basically these formulas look at columns with the checkboxes and if check return the values in the specified cells next to them.
If you want to make it cleaner you can also wrap each of them in an IFNA or IFERROR function to avoid showing an error when nothing is checked.
Try this:
Notes
r.columnStart != 6
– tests for an edit in Column Fv != "TRUE"
– tests for value of "TRUE" (i.e. checkbox is checked).copyTo
– copies the data rather than moves it.