Skip to content

Instantly share code, notes, and snippets.

@jojijacobk
Created August 23, 2020 15:36
Show Gist options
  • Save jojijacobk/fea8f9165373df3c3b1409329cb473cb to your computer and use it in GitHub Desktop.
Save jojijacobk/fea8f9165373df3c3b1409329cb473cb to your computer and use it in GitHub Desktop.
VBA function to get count of cells with a specific colour code
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment