By: Akib Bin Rashid

In reply to Joao.

Hi JOAO
Thank you for your query.
Yes, you can count cells with specific text and font color in a range covering Multiple Columns using VBA.
I will show you two cases regarding how to count cells by font color of specific text.

Case 1: Count Cells by Font Color of Specific Text
First, let me explain the case a bit. Please have a look at the image.

Here, the font color in the specific text “The Prince of the Skies” (in E5) is Red, which is present in both B and C columns. To count the cells that have the same font color of that specific text, you should run the code given below:

Sub CountCellsByFontColor()
Dim rng As Range
Dim lookupCell As Range
Dim count As Long

Set rng = Range("B5:C12")
Set lookupCell = Range("E5")

For Each cell In rng
If cell.Font.Color = lookupCell.Font.Color Then
count = count + 1
End If
Next cell

Range("F5") = count
End Sub

Note:
cell.Font.Color = lookupCell.Font.Color → With this command, Excel is matching the font color of each cell (in Range B5:C12) with the font color of cell E5. If they match, the count variable will increase by 1.

Once you run the code, Excel will show you the result.

Case 2: Count Cells with Specific Text and Font Color
Let’s understand this case first.

Here, the reference text is “Pippo and Clara”. However, the font color is different in B6 and B8.
Now, to count cells by specific text with color, write down the following code:

Sub CountCellsByTextAndColor()
Dim count As Long
Dim tableRange As Range
Dim lookupText As String
Dim lookupColor As Range
Dim cell As Range
lookupText = InputBox("Specific Text: ")

Set tableRange = Range("B5:C12")

Set lookupColor = Range("E5")

count = 0

For Each cell In tableRange
If cell.Value = lookupText And cell.Font.Color = lookupColor.Font.Color Then
count = count + 1
End If
Next cell
Range("E5") = lookupText
Range("F5") = count

End Sub

Once you run the code, you will get an input box.

You have to write the specific text that you desire. Then, on clicking OK, Excel will show the result.

Note:
cell.Value = lookupText And cell.Font.Color = lookupColor.Font.Color → This command is checking two conditions
cell.Value = lookupText: This condition checks if the value of the cell is equal to the value of the lookupText variable.
cell.Font.Color = lookupColor.Font.Color: This condition checks if the font color of the cell is the same as the font color of the lookupColor cell.
If both condition match, the count variable will increase by 1.

Here, the count is 1. Because, for the text (“Pippo and Clara”), the font color matches only once in cell B8.
Thank you. Have a good day!