title: How to count for specific string and color?
body: <p>I've been looking into how to count cells with the countif function, and how to count cells that are colored using scripts and custom functions (like this thing: <a href="http://pastebin.com/4Yr095hV" rel="nofollow noreferrer">http://pastebin.com/4Yr095hV</a>), but how would i count cells with a specific string AND color?</p>
  
  <p>Example, I want to count every cell containing the word "one" that has a fill color of white.</p>
  
  <p>EDIT: I was told to add what i had so far, but I am not sure what was meant by that. For counting cells with a specific string I used:</p>
  
  <p>=COUNTIF(A1:A247,"string")</p>
  
  <p>and for counting cells that are colored i used this what was on this page: <a href="https://webapps.stackexchange.com/questions/23881/google-spreadsheet-calculating-shaded-cells">https://webapps.stackexchange.com/questions/23881/google-spreadsheet-calculating-shaded-cells</a></p>
  
  <p>but i still don't know how to combine these two TOGETHER.</p>
  
  <p>EDIT: For those looking for this answer, I've found a way to utilize the script Tom posted, and adjusted a line within it.</p>
  
  <p>For Tom's script to work with "wildcards", i used something called .indexOf to always look for any cells containing the string (effectively treating it as if there is always a star before and after the string). On line 32 of his script, I altered it to this:</p>
  
  <pre><code>.map   (function(e,i,a) { if (e.toString().toUpperCase().indexOf(this.toString().toUpperCase()) &gt;= 0){ return 1 } else { return 0 } },str))
  </code></pre>
  
  <p>So now whenever I want to look for a White cell containing the string "Apple1", it will count it regardless of if it's written as "OrangeApple1B" or whatever. And the casing doesn't matter since it seems like this script always converts the given string to Upper Case anyways.</p>
  
  <p>I am still trying to find out how to incorporate this on a totally different spreadsheet though (using something like IMPORTRANGE to count cells on a TOTALLY DIFFERENT SHEET using this script)...</p>