title: Count instances of text in excel based on background color
body: <p><img src="https://i.stack.imgur.com/on9kz.jpg" alt="sample excel"></p>
  
  <p>The requirement is a piece of code which can count instances of a string i.e(ABC,DEF,GHK), based on if they are present in a colored cell or not and put the results in a cell below as shown . </p>
  
  <p>Can anyone please advise?</p>
  
  <p>I tried a sample code</p>
  
  <pre><code>Sub Color()
  
  Dim varCounter As String
  Dim color As Integer
  Dim nocolor As Integer
  
  Range("E5").Select
  color= 0
  nocolor= 0
  
        Do Until Selection.Value = ""
                    If Selection.Font.Color = RGB(255, 0, 0) Then
                     color= color+ 1
                       Else
                     nocolor= nocolor+ 1
                     End If
                     Selection.Offset(1, 0).Select
          Loop
    Range("E47").Select
    Selection.Value = no
  
  
    Range("E48").Select
  Selection.Value = color
  
  End Sub
  </code></pre>
  
  <p>This a very simple code which check if the text font is colored or not , buut I couldn't find anything which check for the background color of the cell. </p>
  
  <p>I also tried excel formula , but that with that I can only search for text and count , it doesn't count based on background color of the cell. </p>