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
| Option Explicit
Sub test()
Dim a, b, res(), i As Long, j As Long, n As Long, t As Byte
Dim txt As String, dico As Object
Set dico = CreateObject("Scripting.Dictionary")
dico.CompareMode = 1
'le 1er tableau en feuil1
With Sheets("Feuil1").Range("a1").CurrentRegion
a = .Value: t = 4
ReDim res(1 To UBound(a, 1), 1 To UBound(a, 2))
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
txt = Join(Array(a(i, 1), a(i, 2)), Chr(2))
n = n + 1: .Item(txt) = n
For j = 1 To UBound(a, 2)
res(.Item(txt), j) = a(i, j)
Next
Next
'le 2eme tableau en feuil2
b = Sheets("Feuil2").Range("a1").CurrentRegion.Value
For i = 2 To UBound(b, 1)
txt = Join(Array(b(i, 1), b(i, 2)), Chr(2))
If Not dico.exists(b(i, 3)) Then
t = t + 1: dico(b(i, 3)) = t
If UBound(res, 2) < t Then
ReDim Preserve res(1 To UBound(res, 1), 1 To UBound(res, 2) + 1)
res(1, t) = b(i, 3)
End If
End If
res(.Item(txt), dico(b(i, 3))) = b(i, 4)
Next
End With
End With
'la restitution en feuil3
Application.ScreenUpdating = False
With Sheets("Feuil3").Range("a1")
With .Resize(n, t)
.CurrentRegion.Clear
.Value = res
.BorderAround Weight:=xlThin
.Borders(xlInsideVertical).Weight = xlThin
.Font.Name = "calibri"
.Font.Size = 10
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
With .Rows(1)
.Font.Bold = True
.BorderAround Weight:=xlThin
.Interior.ColorIndex = 44
End With
.Parent.Activate
End With
End With
Application.ScreenUpdating = True
End Sub |
Partager