GomaPile
Active Member
- Joined
- Jul 24, 2006
- Messages
- 334
- Office Version
- 365
- Platform
- Windows
Hi All,
After days of researching through so many forums trying to find some web assistance for counting combined color cells with text, sadly, none of them helped me.
This Function vba code below works fine, but I like to count cells that contains the same color & any form of text together; looking at a range of cells. e.g. If, 5 cells contains data within a range of color cells "Yellow" for instance; it will return the value 5. But if one of the 5 yellow cells doesn't contain text than don't count me.
Can anyone please point me in the right direction that does both criteria in a single cell.
Cell B4 has the color background:
Cell A4 if the value = nothing (cool way to switch the formula On/Off)
Regards
Goma (NASA)
After days of researching through so many forums trying to find some web assistance for counting combined color cells with text, sadly, none of them helped me.
This Function vba code below works fine, but I like to count cells that contains the same color & any form of text together; looking at a range of cells. e.g. If, 5 cells contains data within a range of color cells "Yellow" for instance; it will return the value 5. But if one of the 5 yellow cells doesn't contain text than don't count me.
Can anyone please point me in the right direction that does both criteria in a single cell.
Code:
Function CountCellsByColor(rData As Range, cellRefColor As Range) As Long
'CountCellsByColor(range, color code)
'example =CountCellsByColor(C4:P4,B4)
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Application.Volatile
cntRes = 0
indRefColor = cellRefColor.Cells(1, 1).Interior.Color
For Each cellCurrent In rData
If indRefColor = cellCurrent.Interior.Color Then
cntRes = cntRes + 1
End If
Next cellCurrent
CountCellsByColor = cntRes
End Function
Cell B4 has the color background:
Code:
=IF($A$4<1,"",CountCellsByColor(C4:P4,$B$4))
Regards
Goma (NASA)
Last edited: