I am using this gentlemans script:
http://igoogledrive.blogspot.com/2015/11/google-spreadsheet-sum-of-colored-cells.html
To sum up the value of only colored cells but I get an error message saying "Error TypeError: Cannot read property 'pop' of null (line 15)."
Here is the script he created that I am trying to use:
/**
* @param {range} sumRange Range to be evaluated
* @param {range} colorRef Cell with background color to be searched for in sumRange
* @return {number}
* @customfunction
*/
function sumColoredCells(sumRange,colorRef) {
var activeRange = SpreadsheetApp.getActiveRange();
var activeSheet = activeRange.getSheet();
var formula = activeRange.getFormula().toString();
formula = formula.replace(new RegExp(';','g'),',');
var rangeA1Notation = formula.match(/\((.*)\,/).pop();
var range = activeSheet.getRange(rangeA1Notation);
var bg = range.getBackgrounds();
var values = range.getValues();
var colorCellA1Notation = formula.match(/\,(.*)\)/).pop();
var colorCell = activeSheet.getRange(colorCellA1Notation);
var color = colorCell.getBackground();
var total = 0;
for(var i=0;i<bg.length;i++)
for(var j=0;j<bg[0].length;j++)
if( bg[i][j] == color )
total=total+(values[i][j]*1);
return total;
};
Perhaps Google changed something in the environment that completely breaks this script? I see that it was written a few years back...
I also came across someone with a similar issue and their solution was to replace lines 15 and 20 respectivly thus:
var rangeA1Notation = formula.match(/sumColoredCells\(([^,]*),/).pop();
and
var colorCellA1Notation = formula.match(/,(\w{2,})\)/).pop();
But makes no difference to the error.