My Google Sheet Conditional Formatting rules are full of Strings, like =INDIRECT("Settings!D18").
If I rearrange things on my Settings sheet and D18 becomes X45, is there a way for me to do a global Search/ Replace to reflect that?
For this, use the ConditionalFormatRuleBuilder and the withCriteria() builder.
Sample:
function bulkUpdateConditionalFormatting(){ var sheet = SpreadsheetApp.getActiveSheet(); var rules = sheet.getConditionalFormatRules(); var newRules = []; var newCriteriaValues rules.forEach(function(rule){ var booleanCondition = rule.getBooleanCondition(); Logger.log(booleanCondition.getCriteriaValues()); if (booleanCondition != null && booleanCondition.getCriteriaType() == 'CUSTOM_FORMULA') { var values = booleanCondition.getCriteriaValues() values.forEach(function(value,i){values[i] = value.replace("D18", "D45")}); var newRule = SpreadsheetApp.newConditionalFormatRule() .withCriteria(booleanCondition.getCriteriaType(), values) .setBackground(booleanCondition.getBackground()) .setRanges(rule.getRanges()) .build(); newRules.push(newRule); } }) sheet.setConditionalFormatRules(newRules); }
answerthe question and I will Accept it