1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| Option Explicit
Sub test()
Dim a, w(), t As Byte, i As Long, n As Long, x, y
With Sheets("Sheet1").Cells(1).CurrentRegion
a = .Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For t = 1 To 2
For i = 2 To UBound(a, 1)
If a(i, t) <> "" Then
If Not .exists(a(i, t)) Then
ReDim w(1 To 3)
ReDim tablo(1 To 2, 1 To 1)
Else
w = .Item(a(i, t))
tablo = w(3)
End If
w(t) = w(t) + 1
If UBound(tablo, 2) < Application.Max(w(1), w(2)) Then
ReDim Preserve tablo(1 To 2, 1 To UBound(tablo, 2) + 1)
End If
tablo(t, w(t)) = a(i, t)
w(3) = tablo
.Item(a(i, t)) = w
End If
Next
Next
x = .keys: y = .items
End With
End With
Application.ScreenUpdating = False
'Restitution et mise en forme
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Restitution").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Sheets.Add.Name = "Restitution"
With Sheets("Restitution").Cells(1)
.Parent.Cells.Clear
.Resize(1, UBound(a, 2)) = a
n = 1
For i = 0 To UBound(x)
With .Offset(n).Resize(UBound(y(i)(3), 2), UBound(y(i)(3), 1))
.Value = Application.Transpose(y(i)(3))
.BorderAround Weight:=xlThin
n = n + .Rows.Count
End With
Next
With .CurrentRegion
.Borders(xlInsideVertical).Weight = xlThin
.Font.Name = "calibri"
.Font.Size = 10
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
With .Rows(1)
.Font.Bold = True
.BorderAround Weight:=xlThin
.Cells(1).Interior.ColorIndex = 44
.Cells(2).Interior.ColorIndex = 43
End With
.Columns.AutoFit
End With
.Parent.Activate
End With
Application.ScreenUpdating = True
End Sub |
Partager