Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9831

Change Google Sheet cell background color based on hex value within

$
0
0

So I've been looking online and I am not able to find an answer that is working for me. I have a Google Sheet, and some of the cells within that sheet have hex values in them. What I am trying to do is make it so that the cell background changes to the hex value within that cell, and if need be the font will inverse that color so it's always readable.

I checked How do I change a cell to the color of the hexadecimal value of a cell in Google Spreadsheets? that link which kind of does what I'm looking for but it appears to do the whole range I'm working on, not individual cells.

Here is my code, which like I said isn't doing quite what I want. Seems close, but not there yet.

function onEdit(e) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Color Groups")
    var range = sheet.getRange("A2:G1000");
    range.sort({column: 2, ascending: true});

    var color = e.value;
    var newRange = sheet.getRange("C2:G1000");
    newRange.offset(0, 1).setBackground(color);
}

Any help is appreciated, kinda new to scripts within Google Sheets.


Viewing all articles
Browse latest Browse all 9831

Latest Images

Trending Articles



Latest Images