Ciao,
questa dovrebbe essere la “traduzione” in VBA della tua serie di condizioni.
codice:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:B")) Is Nothing Then
For Each Casella_A In Range("A1:A1000")
Set Casella_B = Casella_A.Offset(0, 1)
If Casella_A <= Casella_B And Casella_A >= 20 And Casella_A < 25 Then
Casella_A.Interior.Color = vbYellow
Casella_B.Interior.ColorIndex = xlColorIndexNone
End If
If Casella_A > Casella_B And Casella_B >= 20 And Casella_B < 25 Then
Casella_A.Interior.ColorIndex = xlColorIndexNone
Casella_B.Interior.Color = vbYellow
End If
If Casella_A <= Casella_B And Casella_A >= 25 And Casella_A < 31 Then
Casella_A.Interior.Color = vbRed
Casella_B.Interior.ColorIndex = xlColorIndexNone
End If
If Casella_A > Casella_B And Casella_B >= 25 And Casella_B < 31 Then
Casella_A.Interior.ColorIndex = xlColorIndexNone
Casella_B.Interior.Color = vbRed
End If
If Casella_A >= Casella_B And Casella_A >= 31 And Casella_A < 115 Then
Casella_A.Interior.Color = vbBlue
Casella_B.Interior.ColorIndex = xlColorIndexNone
End If
If Casella_A < Casella_B And Casella_B >= 31 And Casella_B < 115 Then
Casella_A.Interior.ColorIndex = xlColorIndexNone
Casella_B.Interior.Color = vbBlue
End If
If Casella_A >= Casella_B And Casella_A >= 115 And Casella_A < 121 Then
Casella_A.Interior.Color = RGB(112, 48, 160)
Casella_B.Interior.ColorIndex = xlColorIndexNone
End If
If Casella_A < Casella_B And Casella_B >= 115 And Casella_B < 121 Then
Casella_A.Interior.ColorIndex = xlColorIndexNone
Casella_B.Interior.Color = RGB(112, 48, 160)
End If
If Casella_A <= Casella_B And Casella_A >= 121 Then
Casella_A.Interior.Color = RGB(255, 192, 0)
Casella_B.Interior.ColorIndex = xlColorIndexNone
End If
If Casella_A > Casella_B And Casella_B >= 121 Then
Casella_A.Interior.ColorIndex = xlColorIndexNone
Casella_B.Interior.Color = RGB(255, 192, 0)
End If
If Casella_A > Casella_B And Casella_B < 0 Then
Casella_A.Interior.ColorIndex = xlColorIndexNone
Casella_B.Interior.Color = RGB(255, 128, 255)
End If
If Casella_A < 0 Then
Casella_A.Interior.Color = vbGreen
Casella_B.Interior.ColorIndex = xlColorIndexNone
End If
Next
End If
End Sub
Devi solo copia/incollare il codice nell'editor di VBA che si apre con ALT+F11 e indicare il range che ti interessa al posto di A1:A1000 (indica solo la colonna A, la colonna B viene ottenuta con l'offset).
Tieni presente che le if le ho messe in cascata, come le hai indicate tu, in modo quindi che vengano eseguite tutte ogni volta e che quella che comanda sia l'ultima (cioè se una coppia di valori, come 30-40, soddisfa più di una condizione, la colorazione risultante sarà quella dell'ultima if soddisfatta).
Se vuoi invece che in questi casi sia la prima a comandare devi togliere tutte le end if tranne le ultime due e sostituire tutte le if, tranne le prime due, con ElseIf.
Fammi sapere come va
Ciao