Von Pookie
MrExcel MVP
- Joined
- Feb 17, 2002
- Messages
- 13,686
First thing this morning, I was asked if there was a way to count by colors, which I know there are having seen it on this board many times
However, he wants to know how many ROWS have text of a certain color--not the number of cells. I can't figure out how to update any of the codes that I've found to do so.
He needs to have it count how many rows of each color, not just one specific one. So how many rows have blue text, how many have green text, etc.
I found this on Chip Pearson's site, but like I said, I don't know how to change it for what he needs:
Any ideas?
However, he wants to know how many ROWS have text of a certain color--not the number of cells. I can't figure out how to update any of the codes that I've found to do so.
He needs to have it count how many rows of each color, not just one specific one. So how many rows have blue text, how many have green text, etc.
I found this on Chip Pearson's site, but like I said, I don't know how to change it for what he needs:
The following function will return the number of cells in a range that have either an Interior (background) or Font of a specified color. InRange is the range of cells to examine, WhatColorIndex is the ColorIndex value to count, and OfText indicates whether to return the ColorIndex of the Font (if True) or the Interior (if False).
Code: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)
Any ideas?