Bonjour et bienvenue CyberDid , bonjour à tous ,
Via VBA. Dans la feuille "Liste", cliquer sur le bouton en orange. Dans le classeur, le code est commenté. Le tableau structuré résultat sur la feuille "Objectif" s'appelle "tsPaysIdx".
Le code dans Module1 :
Sub Transposer()
Dim t, tIdx, r, i&, max&, col&, deb, tmp
deb = Timer: Application.ScreenUpdating = False
t = Sheets("Liste").[a1].ListObject.ListColumns(1).DataBodyRange
With Sheets("Objectif")
.[a1].CurrentRegion.Clear
If Not .[a1].ListObject Is Nothing Then .[a1].ListObject.Delete
.[a1].Resize(UBound(t)) = t
.[a1].Resize(UBound(t)).Sort .[a1], 1, Header:=xlNo, MatchCase:=False
.[a1].Resize(UBound(t)).RemoveDuplicates Columns:=1, Header:=xlNo
tIdx = .[a1].CurrentRegion
If Not IsArray(tIdx) Then tmp = tIdx: ReDim tIdx(1 To 1, 1 To 1): tIdx(1, 1) = tmp
ReDim res(1 To UBound(t) + 1, 1 To UBound(tIdx))
For i = 1 To UBound(tIdx): res(1, i) = 1: Next
For i = 1 To UBound(t)
col = Application.Match(t(i, 1), tIdx, 0)
res(1, col) = res(1, col) + 1
If res(1, col) > max Then max = res(1, col)
res(res(1, col), col) = i
Next i
For i = 1 To UBound(tIdx): res(1, i) = tIdx(i, 1): Next
.[a1].CurrentRegion.Clear
.[a1].Resize(max, UBound(res, 2)) = res
.ListObjects.Add(xlSrcRange, .[a1].CurrentRegion, , xlYes).Name = "tsPaysIdx"
.[a1].ListObject.TableStyle = "TableStyleLight10"
.Select
End With
MsgBox "Traitement terminé en " & Format((Timer - deb), "0.000\ sec.")
End Sub