Private Sub Worksheet_Change(ByVal Target As Range)
Dim d As Object, tablo, resu(), i&, x As Variant, n&
Set d = CreateObject("Scripting.Dictionary")
If FilterMode Then ShowAllData 'si la feuille est filtrée
With Range("A1", Range("A" & Rows.Count).End(xlUp))
tablo = .Resize(, 2) 'matrice, plus rapide, au moins 2 éléments
ReDim resu(1 To UBound(tablo), 1 To 2)
For i = 1 To UBound(tablo)
x = CStr(tablo(i, 1))
If IsNumeric(x) Then
x = CDbl(x)
If Not d.exists(x) Then
n = n + 1
d(x) = n 'mémorise la ligne
resu(n, 1) = x
End If
If d.exists(x - 1) Then resu(d(x - 1), 2) = 1 'repère 1 en 2ème colonne
End If
Next
'---restitution---
Application.ScreenUpdating = False
Application.EnableEvents = False 'désactive les évènements
With .Cells(2, 2) 'B2
If n Then
.Resize(n, 2) = resu
.Resize(n, 2).Sort .Cells(1, 2), xlAscending, .Cells(1), , xlAscending, Header:=xlNo 'tri sur 2 colonnes
i = Application.Count(.Cells(1, 2).Resize(n)) + 1 'fonction NB
.Cells(1, 2).Resize(n).ClearContents
End If
.Offset(n).Resize(Rows.Count - n - .Row + 1).ClearContents 'RAZ en dessous
.Cells(i).Insert xlDown, xlFormatFromRightOrBelow 'formats du dessous 'séparation
End With
Application.EnableEvents = True 'réactive les évènements
End With
End Sub