Seigo has attended:
Excel VBA Intro Intermediate course
VBA
How would you count things by colour or format
RE: VBA
Hi Seigo
The following function counts the cells in a range with the same colour background or text depending on the option you set up
Public Function CountByColour(MyRange As Range, _
MyColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
' This function return the number of cells in MyRange with
' a background color, or if OfText is True a font color,
' equal to MyColorIndex.
Dim RangeVar As Range
Application.Volatile True
For Each RangeVar In MyRange.Cells
If OfText = True Then
CountByColour = CountByColour - _
(RangeVar.Font.ColorIndex = MyColorIndex)
Else
CountByColour = CountByColour - _
(RangeVar.Interior.ColorIndex = MyColorIndex)
End If
Next RangeVar
End Function
Hope this helps
Carlos