0

I am trying to call a function when someone check a checkbox. I came up with this so far but it is not working. Checkboxes are in cells F2 and F3

function onEdit(e) {
  var range = e.range
  if(range.getCell() == "F2") {
    resetData()
  }
  else if(range.getCell() == "F3") {
    renameSheet()
  }
}

1 Answer 1

2

It has many ways to do this. The basic one is

function onEdit() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  if (sheet.getRange("F2").isChecked()) {
    resetData()
  } else if (sheet.getRange("F3").isChecked()) {
    renameSheet()
  }
}

Addition with uncheck after the click

function onEdit() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  var range = sheet.getActiveRange()
  if (range.isChecked()) {
    if (range.getA1Notation() == "F2") {
      resetData()
    } else if (range.getA1Notation() == "F3") {
      renameSheet()
    }
    range.uncheck()
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot for your reply. That works well. I am trying to make it work with an installable trigger, I changed the onEdit() to onInstallableEdit() and tried to create a trigger that called onInstallableEdit() and it doesn't do anything. Do you have an idea why ?
I made it work, I made a mistake on the function call. Thanks a lot for your help
I'm happy to help. About onInstallableEdit() I think it won't trigger things, it's just a regular function. This the limit we can do developers.google.com/apps-script/guides/triggers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.