Skip to content

Instantly share code, notes, and snippets.

@redbar0n
Last active April 30, 2020 17:26
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 redbar0n/b08f2b25b5df7bec935bbf00e9454296 to your computer and use it in GitHub Desktop.
Save redbar0n/b08f2b25b5df7bec935bbf00e9454296 to your computer and use it in GitHub Desktop.
Google Sheets - How to format cells through code in Google Sheets. Option 1: Automatically when the spreadsheet opens.
// This does not set the color of a user-selected cell like using getActiveCell does,
// but it necessarily relies on getActiveSheet(), since ranges are defined as referencing cells within sheets.
function setBackgroundOfScriptDeclaredCell() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1");
range.setBackground("red");
}
// Will run when user opens/refreshes spreadsheet.
function onOpen() {
setBackgroundOfScriptDeclaredCell();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment