staticbob
Well-known Member
- Joined
- Oct 7, 2003
- Messages
- 1,079
Hi,
I am using the following code (From CPearson) to count cells of specific colour.
I have the code in my workbook module but I'm just getting #name? when trying to use it ?
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
I am using the following code (From CPearson) to count cells of specific colour.
I have the code in my workbook module but I'm just getting #name? when trying to use it ?
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