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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| 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
'Vide la feuille 3
Sheets(3).Cells.Delete Shift:=xlUp
'Importe les données des feuilles 1 et 2
ActiveWorkbook.RefreshAll
Set dico = CreateObject("Scripting.Dictionary")
dico.CompareMode = 1
'le 1er tableau en feuil1
With Sheets(1).Range("a1").CurrentRegion
a = .Value: t = .Cells(1, Cells.Columns.Count).End(xlToLeft).Column
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(2).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, 10)) Then
t = t + 1: dico(b(i, 10)) = 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, 10)
End If
End If
res(.Item(txt), dico(b(i, 10))) = b(i, 11)
Next
End With
End With
'la restitution en feuil3
Application.ScreenUpdating = False
With Sheets(3).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
'Vide les tableaux en feuille 1 et 2
Dim Plg As Range
Set Plg = Sheets(1).Range("Tech")
Plg.ClearContents
Set Plg2 = Sheets(2).Range("Skill")
Plg2.ClearContents
Application.ScreenUpdating = True
ActiveWorkbook.Save
End Sub |