user2318083
user2318083

Reputation: 587

Google Sheets App Script If/Else Checkbox

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.

Upvotes: 0

Views: 460

Answers (1)

user2318083
user2318083

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

Related Questions