Created
January 5, 2018 12:35
-
-
Save aquiladev/79b626999982d0417932f614c7352238 to your computer and use it in GitHub Desktop.
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
function sumColoredCells(sumRange) { | |
var activeRange = SpreadsheetApp.getActiveRange(); | |
var activeSheet = activeRange.getSheet(); | |
var formula = activeRange.getFormula(); | |
var rangeA1Notation = formula.match(/\((.*)\)/).pop(); | |
var range = activeSheet.getRange(rangeA1Notation); | |
var bg = range.getBackgrounds(); | |
var values = range.getValues(); | |
var sum = 0; | |
for(var i=0;i<bg.length;i++) | |
for(var j=0;j<bg[0].length;j++) | |
if(bg[i][j] == activeRange.getBackground()) | |
sum += parseFloat(values[i][j]); | |
return sum; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment