Last active
August 29, 2015 14:23
-
-
Save tojibon/0f8258853bf831075da5 to your computer and use it in GitHub Desktop.
A Google Spreadsheet Function to count number of cells in a column which all are used selected background colors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
--------------------------------------------------------------------------------------- | |
Returns total number of rows for selected background colors separated by comma, in a column range. | |
@ param string colors - A set of background hex colors separated by comma. Ex: '#ff0000,#000000,#AEAEAE' | |
@ param string rangeSpecification - Column field range of rows. Ex: 'E1:E20' | |
@ return int number of rows with colors listed background colors. | |
--------------------------------------------------------------------------------------- | |
*/ | |
function countCellsWithBackgroundColors(colors, rangeSpecification) { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var backGroundColors = sheet.getRange(rangeSpecification).getBackgrounds(); | |
var colorArray = colors.split(","); | |
var x = 0; | |
for (var i = 0; i < backGroundColors.length; i++) { | |
for (var j = 0; j < backGroundColors[i].length; j++) { | |
for (var c = 0; c < colorArray.length; c++) { | |
if (colorArray[c] == backGroundColors[i][j]) { | |
x++; | |
} | |
} | |
} | |
} | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment