daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumColoredCells(sumRange) {
  2.   var activeRange = SpreadsheetApp.getActiveRange();
  3.   var activeSheet = activeRange.getSheet();
  4.   var formula = activeRange.getFormula();
  5.  
  6.   var rangeA1Notation = formula.match(/\((.*)\)/).pop();
  7.   var range = activeSheet.getRange(rangeA1Notation);
  8.   var bg = range.getBackgrounds();
  9.   var values = range.getValues();
  10.  
  11.   var sum = 0;
  12.   for(var i=0;i<bg.length;i++)
  13.     for(var j=0;j<bg[0].length;j++)
  14.       if(bg[i][j] == activeRange.getBackground())
  15.         sum += parseFloat(values[i][j]);
  16.  
  17.   return sum;
  18. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top