eddiegeorge
Oct 25, 2006, 04:14 AM
In November 2004 Leif 5233 wrote the following regarding counting cells highlighted in a certain colour:
------------------
Create this function:
Function CountCol(SumRange As Range, intColor As Integer) As Integer
Dim I As Integer
Dim Cell As Range
Set SumRange = SumRange.SpecialCells(xlCellTypeAllFormatCondition s)
For Each Cell In SumRange
If Cell.Interior.ColorIndex = intColor Then
I = I + 1
End If
Next Cell
CountCol = I
End Function
Then in the cell where you would like the total, put the following formula:
=CountCol(a1:a100,6)
That formula will show you the total count of all cells with colorindex of 6 (Yellow) in range a1:a100. You can fix it up to use color names if you like, but this works fine for me. There is a listing of basic colorindexes in Excel's help.
Hope this helps,
Leif
-----------------
This works great unless the cell is highlighted as a result of conditional formating. Is there any way of counting cells that are highlighted due to conditional formating?
------------------
Create this function:
Function CountCol(SumRange As Range, intColor As Integer) As Integer
Dim I As Integer
Dim Cell As Range
Set SumRange = SumRange.SpecialCells(xlCellTypeAllFormatCondition s)
For Each Cell In SumRange
If Cell.Interior.ColorIndex = intColor Then
I = I + 1
End If
Next Cell
CountCol = I
End Function
Then in the cell where you would like the total, put the following formula:
=CountCol(a1:a100,6)
That formula will show you the total count of all cells with colorindex of 6 (Yellow) in range a1:a100. You can fix it up to use color names if you like, but this works fine for me. There is a listing of basic colorindexes in Excel's help.
Hope this helps,
Leif
-----------------
This works great unless the cell is highlighted as a result of conditional formating. Is there any way of counting cells that are highlighted due to conditional formating?