Skip to content

Instantly share code, notes, and snippets.

@albertopasqualetto
Created October 20, 2022 12:47
Show Gist options
  • Save albertopasqualetto/9fbec183726e0b7a705fdf02a07a630d to your computer and use it in GitHub Desktop.
Save albertopasqualetto/9fbec183726e0b7a705fdf02a07a630d to your computer and use it in GitHub Desktop.
Copy conditional formatting rule to all the Google sheet
/** @OnlyCurrentDoc */
function copyMyConditionalFormatting() {
var spreadsheet = SpreadsheetApp.getActive();
var base_range = spreadsheet.getRange("B2:X2"); //Starting range
var conditionalFormatRules = spreadsheet.getActiveSheet().getConditionalFormatRules();
for (var i=1; i<=1001-3; i++){ //Which columns
var new_rule = conditionalFormatRules[0].copy //Copy first rule to all sheet
.setRanges([base_range.offset(i, 0)]) //column offset
.build();
conditionalFormatRules.push(new_rule);
}
spreadsheet.getActiveSheet().setConditionalFormatRules(conditionalFormatRules);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment