Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Variation Sh
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
If Not Intersect(Source, [B:B]) Is Nothing Then Variation Sh
End Sub
Sub Variation(Sh As Object)
Dim n&, F As Worksheet, cel As Range
n = Val(Replace(Sh.Name, "S", ""))
If n < 2 Then Exit Sub
Application.ScreenUpdating = False 'accélère la macro
[C5:D28,C30:D30].ClearContents 'RAZ
'---Mises en forme si pas déjà fait...---
[C5:D28,C30:D30].HorizontalAlignment = xlCenter
[C5:C28,C30].NumberFormat = "0.00%"
[D5:D28,D30].Font.Name = "Wingdings"
'---Analyse par cellule---
Set F = Worksheets("S" & n - 1)
For Each cel In [B5:B30]
If IsNumeric(cel) And IsNumeric(F.Range(cel.Address)) Then
If cel <> "" And F.Range(cel.Address) <> 0 Then
cel.Offset(, 1) = cel / F.Range(cel.Address) - 1
With cel.Offset(, 2)
Select Case Sgn(cel.Offset(, 1))
Case 1: .Value = "ì": .Font.ColorIndex = 3 'rouge
Case 0: .Value = "è": .Font.ColorIndex = 5 'bleu
Case -1: .Value = "î": .Font.ColorIndex = 4 'vert
End Select
End With
End If
End If
Next
End Sub