mardi 9 mars 2021

Google Sheets - Only allow one checkbox to be checked in range

I am trying to make it so that only one checkbox is able to be checked at any given time. Here is the code that iI am using that works sometimes.

function onEdit (e) {

  var range1 = SpreadsheetApp.getActive().getRange('A7');
  var range2 = SpreadsheetApp.getActive().getRange('A8');
  var range3 = SpreadsheetApp.getActive().getRange('A9');
  var range4 = SpreadsheetApp.getActive().getRange('A10');

  if(range1.isChecked()) {

    range2.uncheck();
    range3.uncheck();
    range4.uncheck();

  } 
  
  if(range2.isChecked()) {

    range1.uncheck();
    range3.uncheck();
    range4.check();

  } 
  
  if(range3.isChecked()) {

    range1.uncheck();
    range2.uncheck();
    range4.uncheck();

  } 
  
  if(range4.isChecked()) {

    range1.uncheck();
    range2.uncheck();
    range3.uncheck();

  }

}

Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire