javascript - How to change color of a cell if the previous cell contains the hex color name? - Stack Overflow

PHOTO EMBED

Wed Aug 14 2024 09:53:03 GMT+0000 (Coordinated Universal Time)

Saved by @baamn #javascript

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const sh = ss.getSheetByName("Sheet1");
  const hex_colors = sh.getRange('A1:A'+sh.getLastRow()).getValues();
  sh.getRange('B1:B'+sh.getLastRow()).setBackgrounds(hex_colors);
}
content_copyCOPY

You can run the following script (with adjustments based on your scenario) from the script editor and/or create a custom menu to execute it from there if you want a more user friendly way to do that.

https://stackoverflow.com/questions/65944323/how-to-change-color-of-a-cell-if-the-previous-cell-contains-the-hex-color-name?rq