Skip to content

Instantly share code, notes, and snippets.

@hanxue
Created December 9, 2012 08:55
Show Gist options
  • Save hanxue/4243931 to your computer and use it in GitHub Desktop.
Save hanxue/4243931 to your computer and use it in GitHub Desktop.
Highlighting alternate rows in Google Spreadsheets
function colorRowsAlternateSelection() {
var currentSheet = SpreadsheetApp.getActiveSheet();
var currRange = currentSheet.getActiveSelection();
topRow = currRange.getRow();
buttomRow = currRange.getLastRow();
leftCol = currRange.getColumn();
rightCol = currRange.getLastColumn();
colorRows(topRow , buttomRow , leftCol , rightCol );
}
function colorColumns( topRow , buttomRow , leftCol , rightCol ) {
var currentSheet = SpreadsheetApp.getActiveSheet();
for (i=leftCol; i<=rightCol; i++) {
if ( i % 2 == 0) {
currentSheet.getRange(topRow, i , (buttomRow-topRow)+1, 1 ).setBackgroundRGB(235, 235, 235);
} else {
currentSheet.getRange(topRow, i , (buttomRow-topRow)+1, 1 ).setBackgroundRGB(255, 255, 255);
}
}
}
Copy link

ghost commented May 27, 2013

That was easy : add the following function to the native code :

function colorRows( topRow , buttomRow , leftCol , rightCol ) {
var currentSheet = SpreadsheetApp.getActiveSheet();
for (i=topRow; i<=buttomRow; i++) {
if ( i % 2 == 0) {
currentSheet.getRange(i, leftCol , 1, (rightCol-leftCol+1) ).setBackgroundRGB(235, 235, 235);
} else {
currentSheet.getRange(i, leftCol , 1, (rightCol-leftCol+1) ).setBackgroundRGB(255, 255, 255);
}
}
}

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