google apps script - Set global condtional formatting rules programmatically -


i want set background color of every row in "task" column if "status" column's row not blank. easy setup. setting these rules across numerous columns , sheet 1 sheet 100 can tedious.

given sheets have same columns "task" , "status" should possible set conditional rule on every sheet. how can programmatically?

you may use script accomplish task. know, there's no way make conditional formatting script, here's issue. can copy formatting:

  1. make 1 conditional formatting rule on 'key sheet'
  2. run script

here's code add script editor:

function loopsheetscopyformatting() {    var ss = spreadsheetapp.getactivespreadsheet();   var sheets = ss.getsheets();    // define key sheet   var keysheet = ss.getsheetbyname('sheet1'); // change your's   // define range formatting   var rangeaddress = 'a1:a1000'; // change your's    var samplerange = keysheet.getrange(rangeaddress);   var column = samplerange.getcolumn();   var columnend = column + samplerange.getwidth() - 1;   var row = samplerange.getrow();   var rowend = row + samplerange.getheight() - 1;     (var sheetnum = 0; sheetnum < sheets.length; sheetnum++) {       var copytosheet = sheets[sheetnum];      // copy formatting      samplerange.copyformattorange(        copytosheet,         column,         columnend,         row,         rowend);        }  } 

change lines:

var keysheet = ss.getsheetbyname('sheet1'); // change your's 

and one:

var rangeaddress = 'a1:a1000'; // change your's 

and run script once copy farmatting.


Comments