2019-07-07
Conditional formatting based on another cell's colour
stackoverflow
Question

I have a google spreadsheet with numerical data and month names on top.

Is there any way to copy conditional formatting from the bottom row (numerical) to the top one (month names)?

For example, highlight 'April' in green and 'August' in red?

Formatting top row based on the values of the bottom row won't work, since data can change a lot.

g-sheet

Answer
1

How about this:

function copyColors() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Sheet1');
  var cA=sh.getRange(sh.getLastRow(),2,1,sh.getLastColumn()-1).getBackgrounds();
  sh.getRange(1,2,cA.length,cA[0].length).setBackgrounds(cA);
}
Conditional formatting based on another cell's colour
See more ...