Forum Discussion
burningshield
Oct 17, 2025Copper Contributor
Excel: Count cells with specific value + colour
Hi there, I would like to be able to count the number of cells that contain a specific value and are shaded a specific colour. This is for a rota spreadsheet that will be tallying the total number ...
Lorenzo
Oct 20, 2025Silver Contributor
Hi
"Then management can review and manually highlight in green"
There are several shades of green. If managers don't always use exactly the same your count won't work
Note that I'm not at all a VBA expert. Easier options might exist
Option 1
Counts cells in range where cells value = yes and cells RGB Hex color <> FFFFFF
Function CountApprovedDates(targetRange As Range)
'
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim countApproved As Long
Set ws = ActiveSheet
With ws
For Each cell In targetRange.Cells
If LCase(cell.Value) = "yes" Then
If Hex(CStr(cell.Interior.Color)) <> "FFFFFF" Then
countApproved = countApproved + 1
End If
End If
Next cell
End With
CountApprovedDates = countApproved
End Function
Option 2
Counts cells in range where cells value = yes and cells RGB Hex color = 50B000 (Green in the Standard Colors)
Function CountApprovedDates(targetRange As Range)
'
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim countApproved As Long
Set ws = ActiveSheet
With ws
For Each cell In targetRange.Cells
If LCase(cell.Value) = "yes" Then
If Hex(CStr(cell.Interior.Color)) = "50B000" Then
countApproved = countApproved + 1
End If
End If
Next cell
End With
CountApprovedDates = countApproved
End Function