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.
Best Answer
I created a sheet called
colors
and with the code below it will automatically change the background color from #ff00ff format. I included comments for you to understand, but it should be strait forward.https://developers.google.com/apps-script/guides/support/best-practices