title: How to count cell values based on the background color in Spreadsheet
body: <p>I am trying to count the values in a cell based on the background color. Someone I got some help while online search I am not getting the complete solution. Does anyone help me out with this prob. I have sample code script which I got from the online search.</p>
  
  <p>Also the script which am pasting here is grouping the values( For Example if i have a value A in three cells it should return the value as 3 instead it is returning AAA. Can someone help me out with the script to count the values and return it based on the background color</p>
  
  <p>Thanks in Advance,</p>
  
  <p>Here is the script:</p>
  
  <pre><code>function sumBackgroundColors(rangeString, color) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getActiveSheet();
  var sumRange = s.getRange(rangeString);
  var sum = 0;
  var sumRangeBackground = sumRange.getBackgroundColors();
  var sumRangeValues = sumRange.getValues();
  
  for(var row = 0; row &lt; sumRangeBackground.length; row++ ) {
  for(var col = 0; col &lt; sumRangeBackground[0].length; col++ ) {
  if( sumRangeValues[row][col]=="LG M"&amp;&amp; sumRangeBackground[row][col] == color ) {
  sum = sum + parseFloat(sumRangeValues[row][col]);
  
  } 
  }
  }
  return sum;
  }
  </code></pre>