How to change the color of a cell based on RGB data in other cells on Google Sheets

Viewed 32

Is there a way to have cells with RGB values in them and have Google Sheets change the background of a cell based on that value?

Foe example, assume I have three RGB cells and a fourth cell which displays the result of the RGB combination.So I'm looking for this:

200 200 200 <display gray>
  0   0   0 <display black>
  0 256   0 <display green>

Is it possible with existing functions?

Thanks,

L

1 Answers

Try this:

function onEdit() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheets()[1];
  var cell = sheet.getRange("A1").getValue();
  let cellinput = cell.split(',')
  const cellinput2 = cellinput.map((ele)=> (Number(ele)))
  var cell2 = sheet.getRange("B1");

  cell2.setBackgroundRGB(...cellinput2);
}

There is no option to do the same with existing functions whatsoever so a script needs to be used to achieve this.

This is the final result:

enter image description here

Related