Dante Amor | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | ||||||||
2 | 4 | 3 | ||||||
3 | ||||||||
4 | CF | 1 | Manually | |||||
5 | Manually | 2 | Manually | |||||
6 | CF | 1 | Manually | |||||
7 | Manually | Manually | ||||||
8 | Manually | Manually | ||||||
9 | Manually | Manually | ||||||
10 | Manually | Manually | ||||||
Hoja2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C2,F2 | C2 | =CountColor(B4:B10,B2) |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
B4:B6 | Cell Value | =1 | text | NO |
Function CountColor(cRange As Range, cColor As Range) As Long
Dim c As Range
Application.Volatile
For Each c In cRange
If Evaluate("nIntColor(" & c.Address() & ")") = cColor.Interior.Color Then
CountColor = CountColor + 1
End If
Next
End Function
Private Function nIntColor(ByVal miRango As Range) As Double
nIntColor = miRango.DisplayFormat.Interior.Color
End Function
Thank you Dante, this is PERFECT!!!You can use the following CountColor() function, it works for both cells with conditional formatting and cells with manual color.
Dante Amor
A B C D E F 1 2 4 3 3 4 CF 1 Manually 5 Manually 2 Manually 6 CF 1 Manually 7 Manually Manually 8 Manually Manually 9 Manually Manually 10 Manually Manually Hoja2
Cell Formulas Range Formula C2,F2 C2 =CountColor(B4:B10,B2)
Cells with Conditional Formatting Cell Condition Cell Format Stop If True B4:B6 Cell Value =1 text NO
Put the following in a module. In the cell use CountColor function, like in the example above.
VBA Code:Function CountColor(cRange As Range, cColor As Range) As Long Dim c As Range Application.Volatile For Each c In cRange If Evaluate("nIntColor(" & c.Address() & ")") = cColor.Interior.Color Then CountColor = CountColor + 1 End If Next End Function Private Function nIntColor(ByVal miRango As Range) As Double nIntColor = miRango.DisplayFormat.Interior.Color End Function
![]()