
Option Explicit
Function ActiveCondition(Rng As Range) As Integer
Dim i As Long
Dim FC As FormatCondition
Dim Temp As Variant
Dim Temp2 As Variant
If Rng.FormatConditions.Count = 0 Then
ActiveCondition = 0
Else
For i = 1 To Rng.FormatConditions.Count
Set FC = Rng.FormatConditions(i)
Select Case FC.Type
Case xlCellValue
Select Case FC.Operator
Case xlBetween
Temp = GetStrippedValue(FC.Formula1)
Temp2 = GetStrippedValue(FC.Formula2)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) >= CDbl(FC.Formula1) And _
CDbl(Rng.Value) <= CDbl(FC.Formula2) Then
ActiveCondition = i
Exit Function
End If
Else
If Rng.Value >= Temp And _
Rng.Value <= Temp2 Then
ActiveCondition = i
Exit Function
End If
End If
Case xlGreater
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) > CDbl(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Else
If Rng.Value > Temp Then
ActiveCondition = i
Exit Function
End If
End If
Case xlEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) = CDbl(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Else
If Temp = Rng.Value Then
ActiveCondition = i
Exit Function
End If
End If
Case xlGreaterEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) >= CDbl(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Else
If Rng.Value >= Temp Then
ActiveCondition = i
Exit Function
End If
End If
Case xlLess
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) < CDbl(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Else
If Rng.Value < Temp Then
ActiveCondition = i
Exit Function
End If
End If
Case xlLessEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) <= CDbl(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Else
If Rng.Value <= Temp Then
ActiveCondition = i
Exit Function
End If
End If
Case xlNotEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) <> CDbl(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Else
If Temp <> Rng.Value Then
ActiveCondition = i
Exit Function
End If
End If
Case xlNotBetween
Temp = GetStrippedValue(FC.Formula1)
Temp2 = GetStrippedValue(FC.Formula2)
If IsNumeric(Temp) Then
If Not (CDbl(Rng.Value) <= CDbl(FC.Formula1)) And _
(CDbl(Rng.Value) >= CDbl(FC.Formula2)) Then
ActiveCondition = i
Exit Function
End If
Else
If Not Rng.Value <= Temp And _
Rng.Value >= Temp2 Then
ActiveCondition = i
Exit Function
End If
End If
Case Else
Debug.Print "UNKNOWN OPERATOR"
End Select
Case xlExpression
If Application.Evaluate(FC.Formula1) Then
ActiveCondition = i
Exit Function
End If
Case Else
Debug.Print "UNKNOWN TYPE"
End Select
Next
End If
ActiveCondition = 0
End Function
Function GetStrippedValue(CF As String) As String
Dim Temp As String
If InStr(1, CF, "=", vbTextCompare) Then
Temp = Mid(CF, 3, Len(CF) - 3)
If Left(Temp, 1) = "=" Then
Temp = Mid(Temp, 2)
End If
Else
Temp = CF
End If
GetStrippedValue = Temp
End Function
Function CellsByCFColorIndex(InRange As Range, CI As Integer) As String
Dim Count As Long
Dim cell As Range
Dim FCNum As Integer
Dim s As String
For Each cell In InRange.Cells
FCNum = ActiveCondition(cell)
If FCNum > 0 Then
s = s & cell.Address & " = " & cell & vbCrLf
End If
Next
CellsByCFColorIndex = s
End Function
|
For i = 1 To Range("h" & Rows.Count).End(xlUp).Row
If Cells(i, 8) < Cells(i, 11) Then
tex = tex & vbCrLf & Cells(i, 8)
End If
Next
MsgBox "Le celle rosse sono:" & tex |
option explicit
sub test
dim i as long, tex as string
For i = 1 To Range("h" & Rows.Count).End(xlUp).Row
If Cells(i, 8) < Cells(i, 11) Then
tex = tex & vbCrLf & Cells(i, 8).address & " --> " & cells(i, 8)
End If
Next
MsgBox "Le celle rosse sono queste: " & tex
end sub |
