Private Sub Worksheet_Change(ByVal target As Range)
Dim couleur As Range, lig&, P As Range, rc&, i&, v, j&
Set couleur = Columns("Q").Cells 'colonne à adapter
lig = 2 '1ère ligne de couleur
If FilterMode Then ShowAllData
Set P = Range("O1", Range("O" & Rows.Count).End(xlUp)) 'colonne à adapter
rc = P.Rows.Count
Application.ScreenUpdating = False
P.Interior.ColorIndex = xlNone 'RAZ
For i = 1 To rc
If IsNumeric(CStr(P(i))) And P(i).Interior.ColorIndex = xlNone Then
v = -P(i)
For j = i + 1 To rc
If P(j) = v Then
If P(j).Interior.ColorIndex = xlNone Then
Union(P(i), P(j)).Interior.Color = couleur(lig).Interior.Color
lig = lig + 1
If couleur(lig).Interior.ColorIndex = xlNone Then lig = 2 'on reprend les couleurs au début
Exit For
End If
End If
Next j
End If
Next i
End Sub
Private Sub Worksheet_Change(ByVal target As Range)
Dim couleur As Range, lig&, P As Range, rc&, a(), i&, v, j&
Set couleur = Columns("Q").Cells 'colonne à adapter
lig = 2 '1ère ligne de couleur
If FilterMode Then ShowAllData
Set P = Range("O1", Range("O" & Rows.Count).End(xlUp)) 'colonne à adapter
rc = P.Rows.Count
ReDim a(1 To rc) 'tableau des repères
Application.ScreenUpdating = False
P.Interior.ColorIndex = xlNone 'RAZ
For i = 1 To rc
If IsNumeric(CStr(P(i))) And IsEmpty(a(i)) Then
v = -P(i)
For j = i + 1 To rc
If P(j) = v Then
If IsEmpty(a(j)) Then
a(j) = 1 'repère
Union(P(i), P(j)).Interior.Color = couleur(lig).Interior.Color
lig = lig + 1
If couleur(lig).Interior.ColorIndex = xlNone Then lig = 2 'on reprend les couleurs au début
Exit For
End If
End If
Next j
End If
Next i
End Sub