Private Sub CommandButton1_Click()
Dim ncol%, tablo, resu(), i&, n&, j%
If CommandButton1.Caption = "Grouper" Then
On Error Resume Next 'si aucune SpecialCell
UsedRange.Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
With UsedRange: End With 'actualise la barre de défilement verticale
Else
Application.ScreenUpdating = False
If FilterMode Then ShowAllData 'si la feuilleest filtrée
UsedRange.Sort UsedRange.Columns(2), Header:=xlYes 'tri sur les N°
With UsedRange
ncol = .Columns.Count
If ncol = 1 Then ncol = 2
tablo = .Resize(.Rows.Count + 1, ncol) 'matrice, plus rapide (1 ligne de plus)
ReDim resu(1 To Rows.Count, 1 To ncol)
For i = 2 To UBound(tablo) - 1
n = n + 1
For j = 1 To ncol
resu(n, j) = tablo(i, j)
Next j
If tablo(i + 1, 2) <> tablo(i, 2) Then n = n + 1 'saut de ligne
Next i
If n Then .Offset(1).Resize(n - 1, ncol) = resu
End With
End If
CommandButton1.Caption = IIf(CommandButton1.Caption = "Grouper", "Dissocier", "Grouper")
End Sub