title: Excel module - VBA: Function to count colored cells, if condition is met
body: <p>people!</p>
  
  <p>I do not often refer to VBA in Excel, but when I do, I find answer by Googling.
  However, there is no answer for my current need.</p>
  
  <p>I have following function to count colours in range (possible source - <a href="http://www.ozgrid.com/VBA/sum-count-cells-by-color.htm" rel="nofollow noreferrer">http://www.ozgrid.com/VBA/sum-count-cells-by-color.htm</a>):</p>
  
  <pre><code>    Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
  
      Dim rCell As Range
      Dim lCol As Long
      Dim vResult
  
      lCol = rColor.Interior.Color
  
  
      If SUM = True Then
          For Each rCell In rRange
              If rCell.Interior.Color = lCol Then
                  vResult = WorksheetFunction.SUM(rCell)
              End If
          Next rCell
      Else
          For Each rCell In rRange
              If rCell.Interior.Color = lCol Then
                  vResult = 1 + vResult
              End If
          Next rCell
      End If
  
      ColorFunction = vResult
  End Function
  </code></pre>
  
  <p>I have tried to extend it to count colours in specific range, if condition is met, but failed.</p>
  
  <p>I ask you, dear colleagues, to help me to extend the function to fulfill the need:</p>
  
  <p><strong>count number of colours in specific range, if word "foo" is met in another range</strong>.</p>