1

I have a custom formula that I've been using within the conditional formatting rules. However I am trying to write a script that builds the rules automatically on open so that they 'reset' to the correct order (the ranges get messed up when rearranging cells) The code I currently have is:

function onOpen() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange("C1:D600");

  var rule = SpreadsheetApp.newConditionalFormatRule()
                           .whenFormulaSatisfied(=$E1="x")
                           .setBackground("red")
                           .setRanges([range])
                           .build();

  var rules = sheet.getConditionalFormatRules();

  rules.push(rule);
  sheet.setConditionalFormatRules(rules);
}

In the conditional formatting menu I have it set to Custom Formula Is... =$E1="x"

How can I get that formula to work within the script conditional format rule builder? I get syntax errors for it currently.

RubioRic
  • 2,442
  • 4
  • 28
  • 35

1 Answers1

1

You just need to place the formula in quotation marks as it is a string:

'=$E1="x"'
webstermath
  • 555
  • 1
  • 5
  • 14