google-sheetsgoogle-apps-scriptcheckbox

If checkbox checked set values


I have a problem as follows. if cell A6 is checked then cell G6 will be set to 0.5 and the rest is 0 and i want to automatic do that This is my table And this is my code . I really appreciate that

function setvalues() {   
  var ss =  SpreadsheetApp.getActiveSpreadsheet();   
  var sheet = ss.getSheets()[0];   
  if (sheet.getRange('A6').isChecked() === 'TRUE') {
     sheet.getRange('I6').setValue(0.5);   
  } else {
     sheet.getRange('G6').setValue(0);    
  } 
}

Solution

  • function setvalues() {   
      var ss =  SpreadsheetApp.getActiveSpreadsheet();   
      var sheet = ss.getSheets()[0];   
      if (sheet.getRange('A6').isChecked()) {
         sheet.getRange('I6').setValue(0.5);   
      } else {
         sheet.getRange('G6').setValue(0);    
      } 
    }
    

    Range.isChecked() returns a boolean