Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda