# Thread: Count Cells that contain red text (Win2k, Excel 2k SR-1)

1. ## Count Cells that contain red text (Win2k, Excel 2k SR-1)

Is it possible with a function to count the number of cells in a given range in which there is red text? I set up a simple macro while entering data that would take a cell and apply two design formats: Selection.Font.ColorIndex=3 and Selection.Font.Bold=True just so I could pick out those cells easily. I'd love to have a count of all cells that match these conditions.

2. ## Re: Count Cells that contain red text (Win2k, Excel 2k SR-1)

Public Function CountRed(rngSelected As Range) As Double
Dim rngCell As Range
Application.Volatile 'oops, forgot this first post
CountRed = 0
For Each rngCell In rngSelected
If rngCell.Font.ColorIndex = 3 Then CountRed = CountRed + 1
Next rngCell
End Function

3. ## Re: Count Cells that contain red text (Win2k, Excel 2k SR-1)

Perfect! It works! Thanks!

4. ## Re: Count Cells that contain red text (Win2k, Excel 2k SR-1)

John,
Out of curiosity, any significance to making the function Double rather than Long?

5. ## Re: Count Cells that contain red text (Win2k, Excel 2k SR-1)

Haste, and because Long doesn't cover all the cells in one WS in the unlikely event a huge range is selected? <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

6. ## Re: Count Cells that contain red text (Win2k, Excel 2k SR-1)

Thanks. I just wondered if there might be some (microscopic) performance improvement of using Double versus Long, say.
FWIW, in terms of not covering all the cells, are you thinking of Integer? Maximum value of a Long variable is > 2 billion, I think...

7. ## Re: Count Cells that contain red text (Win2k, Excel 2k SR-1)

Colin, I think that I wasn't thinking!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•