S
snowing
Hello,
Does anyone know how I could take the count font color code below, an
add it to a macro so that it will execute at the end of my macro an
displays a message box using "msgbox" with the total amount of cel
with the font color red with out having to ad
"=COUNTBYCOLOR(A1:A10,3,FALSE)" to a cell on the spread sheet.
Also, the range of cells with be different each time.
Thanks,
*****************************************
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng
End Function
You can call this function from a worksheet cell with a formula like
=COUNTBYCOLOR(A1:A10,3,FALSE
Does anyone know how I could take the count font color code below, an
add it to a macro so that it will execute at the end of my macro an
displays a message box using "msgbox" with the total amount of cel
with the font color red with out having to ad
"=COUNTBYCOLOR(A1:A10,3,FALSE)" to a cell on the spread sheet.
Also, the range of cells with be different each time.
Thanks,
*****************************************
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with
' a background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True
For Each Rng In InRange.Cells
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng
End Function
You can call this function from a worksheet cell with a formula like
=COUNTBYCOLOR(A1:A10,3,FALSE