Option Explicit
Enum d
adInteger = 3
adDouble = 5
adDecimal = 14
adChar = 129
End Enum
Sub transpose()
Dim Obj As Object, Nb As Object: Set Obj = CreateObject("ADODB.Recordset"): Set Nb = CreateObject("ADODB.Recordset") 'on creer la collection
Obj.Fields.Append "Name", adChar, 50
Obj.Open
Nb.Fields.Append "Name", adChar, 50
Nb.Fields.Append "NB", adInteger, 4
Nb.Open
Dim Lib As String, L As Integer, nom As String, X As Integer, col As Integer
Worksheets("feuil2").UsedRange.ClearContents
With Worksheets("feuil1").Range("A1").CurrentRegion
nom = .Cells(1, 1)
col = 0
For X = 1 To .Rows.Count
If Not CBool(InStr(1, Lib, "©" & .Cells(X, 2) & "©")) Then
col = col + 1
Sheets("feuil2").Range("A1").Offset(, col) = .Cells(X, 2)
Lib = Lib & "©" & .Cells(X, 2) & "©"
End If
Obj.AddNew 'on ajoute un enregistrement à la collection
Nb.Filter = "Name='" & Replace(.Cells(X, "A"), "'", "''") & "'"
If Nb.EOF Then Nb.AddNew
Obj("Name") = .Cells(X, "A"): Nb("Name") = .Cells(X, "A")
Nb("NB") = Nb("NB") + 1
Obj.Update: Nb.Update
Nb.Filter = ""
Obj.MoveFirst: Nb.MoveFirst
Nb.Sort = "NB Desc"
Next
End With
Obj.Filter = "Name='" & Replace(Nb("Name"), "'", "''") & "'"
If Not Obj.EOF Then Sheets("feuil2").Range("A2").CopyFromRecordset Obj
End Sub