
Option Explicit
Sub FormatCondi()
Dim FC As FormatCondition, F1, F2
Dim Num As Long, Cella As Range
For Each Cella In [A5:G30]
Cella.Select
For Each FC In ActiveCell.FormatConditions
If FC.Type = xlCellValue Then
F1 = Evaluate(FC.Formula1)
Select Case FC.Operator
Case xlBetween: If ActiveCell >= F1 And ActiveCell <= Evaluate(FC.Formula2) Then Exit For
Case xlEqual: If ActiveCell = F1 Then Exit For
Case xlGreater: If ActiveCell > F1 Then Exit For
Case xlGreaterEqual: If ActiveCell >= F1 Then Exit For
Case xlLess: If ActiveCell < F1 Then Exit For
Case xlLessEqual: If ActiveCell <= F1 Then Exit For
Case xlNotBetween: If ActiveCell < F1 _
Or ActiveCell > Evaluate(FC.Formula2) Then Exit For
Case xlNotEqual: If ActiveCell <> F1 Then Exit For
End Select
Else
If Evaluate(FC.Formula1) Then Exit For
End If
Next FC
If Not FC Is Nothing Then Num = Num + 1 'FC.Interior.ColorIndex
Next
[A1] = Num
End Sub |
Option Explicit
Sub FormatCondi()
Dim FC As FormatCondition, F1, F2
Dim Num As Long, Cella As Range
For Each Cella In [A5:G30]
Cella.Select
For Each FC In ActiveCell.FormatConditions
If FC.Type = xlCellValue Then
F1 = Evaluate(FC.Formula1)
Select Case FC.Operator
Case xlBetween: If ActiveCell >= F1 And ActiveCell <= Evaluate(FC.Formula2) Then Exit For
Case xlEqual: If ActiveCell = F1 Then Exit For
Case xlGreater: If ActiveCell > F1 Then Exit For
Case xlGreaterEqual: If ActiveCell >= F1 Then Exit For
Case xlLess: If ActiveCell < F1 Then Exit For
Case xlLessEqual: If ActiveCell <= F1 Then Exit For
Case xlNotBetween: If ActiveCell < F1 _
Or ActiveCell > Evaluate(FC.Formula2) Then Exit For
Case xlNotEqual: If ActiveCell <> F1 Then Exit For
End Select
Else
If Evaluate(FC.Formula1) Then Exit For
End If
Next FC
If Not FC Is Nothing Then
If FC.Interior.ColorIndex = 3 Then Num = Num + 1 'Conta solo se trova il colore Rosso
End If
Next
[A1] = Num
End Sub |
Public Function FormatCondi(r As Range, n As Integer)
Dim FC As FormatCondition, F1, F2
Dim Num As Long, cella As Range
For Each cella In r
cella.Select
For Each FC In ActiveCell.FormatConditions
If FC.Type = xlCellValue Then
F1 = Evaluate(FC.Formula1)
Select Case FC.Operator
Case xlBetween: If ActiveCell >= F1 And ActiveCell <= Evaluate(FC.Formula2) Then Exit For
Case xlEqual: If ActiveCell = F1 Then Exit For
Case xlGreater: If ActiveCell > F1 Then Exit For
Case xlGreaterEqual: If ActiveCell >= F1 Then Exit For
Case xlLess: If ActiveCell < F1 Then Exit For
Case xlLessEqual: If ActiveCell <= F1 Then Exit For
Case xlNotBetween: If ActiveCell < F1 _
Or ActiveCell > Evaluate(FC.Formula2) Then Exit For
Case xlNotEqual: If ActiveCell <> F1 Then Exit For
End Select
Else
If Evaluate(FC.Formula1) Then Exit For
End If
Next FC
If Not FC Is Nothing Then
If FC.Interior.ColorIndex = n Then Num = Num + 1 'Conta solo se trova il colore specificato come .ColorIndex
End If
Next
FormatCondi = Num
End Function |
