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

139
Views
Is it possible to remove a conditional formatting rule created via ConditionalFormatRuleBuilder

I am making custom conditional formatting rules using this method: ConditionalFormatRuleBuilder.

However, If I ever update it, say the color in .setBackground("#FF0000"), and run it again, it creates a new conditional formatting rule that conflicts with the original one.

What I want to know, is in that example is there a way to remove the rule defined as rule? For example is there an opposite of rules.push(rule);? Something like rules.remove(rule); ?

Here's an example from my code. I currently have this:

var rule1 = SpreadsheetApp.newConditionalFormatRule()
        .whenTextEqualTo(s1)
        .setBackground(s1c)
        .setRanges([r])
        .build();

var rules = curSheet.getConditionalFormatRules();
      rules.push(rule1);

curSheet.setConditionalFormatRules(rules);

Would it be possible to remove the rule defined as rule1?

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

0

If you highlight your entire sheet and select Conditional Formatting from the menu, you will see a list of all of the active format rules on the right of the screen.

The order that the rules in that pane is the same order of the rules in the .getConditionalFormatRules() array.

So you can use splice() to remove which ever rule(s) you want

function deleteFormat(){
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName("Sheet1");
  var rules = sheet.getConditionalFormatRules();
  
  // if you want to remove rules starting at the 4th rule and delete only 1 rule. 
  rules.splice(3,1);
  sheet.setConditionalFormatRules(rules);
}

I tested it on a sample sheet, and it worked. If you have any issues, add a comment and I will look into it.

Also, if you want to edit a rule programmatically, you can use slice with the builder.

  1. Build your rules as normal
  2. Get the list of rules
  3. Use slice('position to remove', 1, newRule)
  4. Set the rules

This will remove the old rule at that position in the array, and replace it with the new one.

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!