Private Sub Worksheet_Activate()
' 2 paramètres : nom de la feuille source - liste des 3 colonnes (lettres)
Const FeuilSource = "Feuil1", colonnes = "A F H"
Dim cols, wksSource As Worksheet, der&, x, i&, t, i0&, n&
Application.ScreenUpdating = False: cols = Split(colonnes): Set wksSource = Sheets(FeuilSource)
With Me
.Columns("a:d").Clear
For Each x In Split(colonnes): i = i + 1: wksSource.Range(x & 1).EntireColumn.Copy .Columns(i): Next
der = .Cells(Rows.Count, 1).End(xlUp).Row
With .Range("a1").Resize(der, 4)
.Sort key1:=[a1], order1:=1, key2:=[b1], order2:=1, key3:=[c1], order3:=1, Header:=1, MatchCase:=False
t = .Value
End With
t(1, 4) = "Qté": i0 = 2: n = 1
For i = 2 To UBound(t)
If t(i, 1) <> t(i0, 1) Or t(i, 2) <> t(i0, 2) Or t(i, 3) <> t(i0, 3) Then
n = n + 1: t(n, 4) = i - i0
t(n, 1) = t(i0, 1): t(n, 2) = t(i0, 2): t(n, 3) = t(i0, 3)
i0 = i
End If
Next i
If t(i0, 1) & t(i0, 2) & t(i0, 3) <> "" Then
n = n + 1: t(n, 4) = i - i0
t(n, 1) = t(i0, 1): t(n, 2) = t(i0, 2): t(n, 3) = t(i0, 3)
End If
.Columns("a:d").Clear
With .Range("a1").Resize(n, 4)
.Value = t: .Borders.LineStyle = xlContinuous: .Columns.AutoFit
.Rows(1).Font.Bold = True: .Rows(1).Interior.Color = RGB(220, 250, 220)
End With
End With
End Sub