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()
  }
}
player0
  • 124,011
  • 12
  • 67
  • 124
Cacadours
  • 25
  • 6

1 Answers1

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()
  }
}
zummon
  • 906
  • 3
  • 9
  • 27
  • 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 ? – Cacadours May 01 '20 at 19:51
  • I made it work, I made a mistake on the function call. Thanks a lot for your help – Cacadours May 01 '20 at 20:13
  • 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 https://developers.google.com/apps-script/guides/triggers – zummon May 02 '20 at 02:30