title: Total number of cells containing a specific font color
body: <p>I'm Trying to create a program to <strong>total the amount of cells containing green and red font in column A among all the sheets in the workbook.</strong></p>
  
  <p>In the provided code below the code it counts <strong>ALL</strong> the cells containing green and red font in <strong>column A</strong> of the worksheets.</p>
  
  <p>Please be sure to leave a comment if you can guide me in the right direction!</p>
  
  <p>I also made an example google sheet of what im trying to accomplish: <a href="https://docs.google.com/spreadsheets/d/1yLfCxaT-cIl_W77Y67xdg_ZTSQlg9X2a5vxAH4JtDpk/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1yLfCxaT-cIl_W77Y67xdg_ZTSQlg9X2a5vxAH4JtDpk/edit?usp=sharing</a></p>
  
  <pre><code>' If it's not going to return something, you can define this as a procedure (sub) and not a function
  Sub Test_It()
  
      Dim mySheet As Worksheet ' Define as worksheet if you're going to loop through sheets and none is a Graph/Chart sheet
  
      Dim printRow As Integer ' Beware that integer it's limited to 32k rows (if you need more, use Long)
      printRow = 2
  
  
      For Each mySheet In ThisWorkbook.Sheets ' use the mySheet object previously defined
  
          Range("N" &amp; printRow).Value = "Sheet Name:"
          Range("O" &amp; printRow).Value = mySheet.Name
          Range("P" &amp; printRow).Value = "Approval:"
          Range("Q" &amp; printRow).Value = SumGreen(mySheet) ' you can pass the sheet as an object
          Range("R" &amp; printRow).Value = "Refused:"
          Range("S" &amp; printRow).Value = SumRed(mySheet)
          printRow = printRow + 1
      Next mySheet
  
  End Sub
  
  -------------------------------------------
  
  Function SumGreen(mySheet As Worksheet) As Long ' define the type the function is going to return
  
      Dim myCell As Range
  
      Dim counter As Long
  
      For Each myCell In mySheet.UsedRange.Columns("A") ' UsedRange is the range that has information
  
          If myCell.Font.Color = RGB(112, 173, 71) Then ' 255 is red, not green, change to whatever you need
  
              counter = counter + 1 ' change to counter + mycell.value if you have values and you want to sum them
  
          End If
  
      Next myCell
  
      ' Set the function to return the counter
      SumGreen = counter
  
  End Function
  
  -------------------------------------------
  
  
  Function SumRed(mySheet As Worksheet) As Long ' define the type the function is going to return
  
      Dim myCell As Range
  
      Dim counter As Long
  
      For Each myCell In mySheet.UsedRange.Columns("A") ' UsedRange is the range that has information
  
          If myCell.Font.Color = 255 Then ' 255 is red, not green, change to whatever you need
  
              counter = counter + 1 ' change to counter + mycell.value if you have values and you want to sum them
  
          End If
  
      Next myCell
  
      ' Set the function to return the counter
      SumRed = counter
  
  End Function
  
  </code></pre>