Skip to content

Instantly share code, notes, and snippets.

@zaemyung
Last active April 9, 2021 21:13
Show Gist options
  • Save zaemyung/0750cd0d1f2f5bc1826d1e2ae3cad94f to your computer and use it in GitHub Desktop.
Save zaemyung/0750cd0d1f2f5bc1826d1e2ae3cad94f to your computer and use it in GitHub Desktop.
Google App macro script for coloring cells that are selected disjointly in Google Sheets
function colorSelectedRangeGreen() {
var sel = SpreadsheetApp.getActive().getSelection().getActiveRangeList().getRanges();
for(var i = 0; i < sel.length; i++){
var cell = sel[i].setBackground("#93c47d");
}
}
function colorSelectedRangePink() {
var sel = SpreadsheetApp.getActive().getSelection().getActiveRangeList().getRanges();
for(var i = 0; i < sel.length; i++){
var cell = sel[i].setBackground("#ffcccc");
}
}
function colorSelectedRangeBlue() {
var sel = SpreadsheetApp.getActive().getSelection().getActiveRangeList().getRanges();
for(var i = 0; i < sel.length; i++){
var cell = sel[i].setBackground("#b3d9ff");
}
}
@zaemyung
Copy link
Author

zaemyung commented Apr 9, 2021

To use the macros in Google Sheets:

  1. Go to Tools -> Script editor -> Paste the codes.
  2. Then, go to Tools -> Macros -> Import -> Select the functions.
  3. Can optionally assign shortcut keys by Tools -> Macros -> Manage macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment