Re le forum,
Pas si simple si les données de la feuille source ne sont pas ordonnées
Une solution un peu tordue
Option Explicit
Sub test()
Dim dico As Object, SL As Object, e
Dim a, b(), c(), posR, posC, i As Long, j As Long
Set dico = CreateObject("Scripting.Dictionary")
Set SL = CreateObject("System.Collections.SortedList")
With Sheets(1).Range("a1").CurrentRegion 'feuille source
a = .Value
For i = 2 To UBound(a, 1)
For j = 1 To 2
dico(a(i, j)) = IIf(j = 1, dico(a(i, j)) + 1, dico(a(i, j)) + 0)
Next
Next
'Détermine l'ordre des en-têtes
For Each e In dico
SL(dico(e)) = e
Next
ReDim b(1 To SL.Count)
For i = SL.Count - 1 To 0 Step -1
b(UBound(b, 1) - i) = SL.GetByIndex(i)
Next
'Ecriture dans le tableau final
ReDim c(1 To UBound(b, 1) + 1, 1 To UBound(b, 1) + 1)
For i = 1 To UBound(b, 1)
c(1, i + 1) = b(i)
c(i + 1, 1) = b(i)
Next
For i = 2 To UBound(a, 1)
posR = Application.Match(a(i, 2), b, 0)
posC = Application.Match(a(i, 1), b, 0)
c(posR + 1, posC + 1) = a(i, 4)
c(posC + 1, posR + 1) = a(i, 3)
Next
End With
Application.ScreenUpdating = False
'Restitution et mise en forme
With Sheets(2).Cells(1).Resize(UBound(c, 1), UBound(c, 2))
.CurrentRegion.Clear
.Value = c
With .Rows(1)
With .Offset(, 1).Resize(, .Columns.Count - 1)
.Interior.ColorIndex = 36
End With
End With
With .Columns(1)
With .Offset(1).Resize(.Rows.Count - 1)
.Interior.ColorIndex = 43
End With
End With
.BorderAround Weight:=xlThin
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideHorizontal).Weight = xlThin
.Font.Name = "calibri"
.Font.Size = 10
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.Columns.ColumnWidth = 15
With .Offset(1, 1).Resize(.Rows.Count - 1, .Columns.Count - 1)
.SpecialCells(4).Interior.ColorIndex = 15
End With
.Parent.Activate
End With
Set dico = Nothing: Set SL = Nothing
Application.ScreenUpdating = True
End Sub
klin89