Option Explicit
Private AncIndice As Long, Posit() As Long, Cible As Interior, Couleur As Long, ÇaTourne As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
Dim TNum(1 To 10, 1 To 1) As Long, N As Long, P As Long
If AncIndice > 0 Then
For N = 1 To 10: TNum(Posit(N), 1) = N: Next N
N = Target.Value
TNum(Posit(AncIndice), 1) = N: TNum(Posit(N), 1) = AncIndice
Application.EnableEvents = False
Me.[D2:D11].Value = TNum
Application.EnableEvents = True
End If
ChangerLesCouleurs
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim TNum(), L As Long
If Intersect(Me.[D2:D11], Target) Is Nothing Then
ÇaTourne = False: AncIndice = 0
Else
TNum = Me.[D2:D11].Value: ReDim Posit(1 To 10): AncIndice = Target.Value
For L = 1 To 10: Posit(TNum(L, 1)) = L: Next L
Set Cible = Target.Interior: Couleur = Cible.Color
If ÇaTourne Then Exit Sub
ÇaTourne = True
While ÇaTourne: DoEvents
If Cible.Color <> Couleur Then
Couleur = Cible.Color: ChangerLesCouleurs: End If: Wend: End If
End Sub
Sub ChangerLesCouleurs()
Dim Rng As Range, TCoul(1 To 10), Cel As Range
Set Rng = Range("D2:D11")
For Each Cel In Rng
TCoul(Cel.Value) = Cel.Interior.Color
Next Cel
Set Rng = Range("G2:Q11")
For Each Cel In Rng
Cel.Interior.Color = TCoul(Cel.Value)
Next Cel
End Sub