Reputation: 587
It's been a while since I've coded and am currently stuck with Google Sheets App Script. I want two check boxes in two different col, one checkbox for "Accepted" entries and the other for "Rejected" entries. I understand I currently have it set up incorrectly but how would I do an if else statement for determining where to input the data according to which checkbox is checked.
Here's the code below, I currently only have it working for one of the checkbox rows, it will not handle the other row of checkboxes. Currently I have the main sheet page and two other ones named "Rejected" and "Accepted" I would like to have them organize according to which checkbox is checked.
"Rejected" checkbox is located on column 4
"Accepted" checkbox is located on column 3
When "Accepted" checkbox is checked I would like that row of data to get copied onto the "Accepted" sheet. Same goes for the "Rejected" sheet as well with rejected data.
Currently checkbox only work for either "Accepted" or "Rejected" checkboxes, not both. I would like for it to work for both columns of checkboxes.
function onEdit(e){
const src = e.source.getActiveSheet();
const r = e.range;
if (src.getName() != "Suggestions" || r.columnStart != 4 || r.rowStart == 1)
return;
const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Rejected");
src.getRange(r.rowStart,1,1,4).moveTo(dest.getRange(dest.getLastRow()+1,1,1,4));
src.deleteRow(r.rowStart);
if (src.getName() != "Suggestions" || r.columnStart != 3 || r.rowStart == 1)
return;
const dest2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Accepted");
src.getRange(r.rowStart,1,1,4).moveTo(dest2.getRange(dest2.getLastRow()+1,1,1,4));
src.deleteRow(r.rowStart);
}
Upvotes: 0
Views: 460
Reputation: 587
This is what I came up with and it seems to work fine. Now that I've gotten this going, is there a way to return the data back to the main sheet if the checkbox is unchecked?
function onEdit(e){
const src = e.source.getActiveSheet();
const r = e.range;
if (src.getName() == "Suggestions" && r.columnStart == 3){
const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Accepted");
src.getRange(r.rowStart,1,1,4).moveTo(dest.getRange(dest.getLastRow()+1,1,1,4));
src.deleteRow(r.rowStart);
} else if (src.getName() == "Suggestions" && r.columnStart == 4){
const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Rejected");
src.getRange(r.rowStart,1,1,4).moveTo(dest.getRange(dest.getLastRow()+1,1,1,4));
src.deleteRow(r.rowStart);
}
return;
}
Upvotes: 1