Skip to content

Instantly share code, notes, and snippets.

@gmaclennan
Last active January 4, 2016 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmaclennan/8610640 to your computer and use it in GitHub Desktop.
Save gmaclennan/8610640 to your computer and use it in GitHub Desktop.
Google Sheets update cell value from cell colour (hex code)
// Will update the value of the cell to the hex value of the color of the cell
// It is triggered by typing a "#" into the cell
// Unfortunately changing the color of a cell does not trigger an edit event in sheets
// Will not work in the new version of Google Sheets
function onEdit(e) {
var cell, value;
var values = e.range.getValues();
for (var i=0; i < values.length; i++) {
for (var j=0; j < values[i].length; j++) {
value = values[i][j];
if (typeof value === "string" && value.substring(0,1) === "#") {
cell = e.range.getCell(i+1, j+1);
cell.setValue(cell.getBackground());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment