Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

635
Views
Why aren't my IF conditions being met? (checkbox.isChecked(), and checkbox == true methods not working)

I'm attempting to apply borders to cells conditionally via apps script, but my code is not registering the two (obviously met) conditions. Looking for a logic and syntax check <3

Sheet: stackoverflow noobs can't attach images so here's a link

Code:

function doBorders() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let sss = ss.getActiveSheet();
  let doBorder = sss.getRange("A5");
  let checkBox = sss.getRange("B5");
  let checkState = checkBox.isChecked();
    let bRow1 = sss.getRange("A1:B1");
    let bRow2 = sss.getRange("A2:B2");
    let bRow3 = sss.getRange("A3:B3");

  if (doBorder == "Do Borders:" && checkState == true) {
    bRow1.setBorder(false, false, true, false, false, false,'Black', SpreadsheetApp.BorderStyle.SOLID);
    bRow2.setBorder(false, false, true, false, false, false,'Black', SpreadsheetApp.BorderStyle.SOLID);
    bRow3.setBorder(false, false, true, false, false, false,'Red', SpreadsheetApp.BorderStyle.SOLID);
    Logger.log('Conditions met. Borders added.');

    } else
      bRow1.setBorder(false, false, false, false, false, false);
      bRow2.setBorder(false, false, false, false, false, false);
      bRow3.setBorder(false, false, false, false, false, false);
      Logger.log('Conditions not met. No borders.');
}

I've tried both checkBox == true and checkState == true. Same result.

Execution Log: "Conditions not met. No borders."

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let checkBox = sss.getRange("B5") gets a Range object, which is different from the value in that cell. To test the value, use Range.getValue(), like this:

  const checkBox = sss.getRange('B5');
  const checkBoxValue = checkBox.getValue();
  if (checkBoxValue === true) {
    // do sfuff...
  } else {
    // do other stuff...
  }

Also observe the { curly braces } after the else.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!