Peter Davison
Active Member
- Joined
- Jun 4, 2020
- Messages
- 444
- Office Version
- 365
- Platform
- Windows
Is it possible to count blank cells that have a specific colour
Is it possible to count blank cells that have a specific colour
'Code created by Sumit Bansal from https://trumpexcel.com
Function GetColorCount(CountRange As Range, CountColor As Range)
Dim CountColorValue As Integer
Dim TotalCount As Integer
CountColorValue = CountColor.Interior.ColorIndex
Set rCell = CountRange
For Each rCell In CountRange
If rCell.Interior.ColorIndex = CountColorValue Then
TotalCount = TotalCount + 1
End If
Next rCell
GetColorCount = TotalCount
End Function
Option Explicit
Sub countcolor()
Dim rng As Range, cell As Range, count&
Set rng = ActiveSheet.UsedRange
For Each cell In rng.SpecialCells(xlCellTypeBlanks)
If cell.Interior.Color = vbYellow Then count = count + 1
Next
msgbox count
End Sub