Bonsoir à tous,
Une autre façon de procéder :
Option Explicit
Sub fusion()
Dim a, w(), e, i As Long, t As Byte, txt As String, dico As Object
Set dico = CreateObject("Scripting.Dictionary")
dico.CompareMode = 1: t = 0
For Each e In Array("Fournisseur 1", "Fournisseur 2")
a = Sheets(e).Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
txt = Join(Array(a(i, 1), a(i, 2)), Chr(2))
If Not dico.exists(txt) Then
ReDim w(1 To 7)
w(1) = a(i, 1): w(2) = a(i, 2)
Else
w = dico(txt)
End If
w(3 + t) = a(i, 3)
w(5 + t) = w(5 + t) + a(i, 4)
dico(txt) = w
Next
t = t + 1
Next
For Each e In dico.keys
w = dico(e)
w(7) = w(5) + w(6)
dico(e) = w
Next
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Restitution").Delete
Sheets.Add().Name = "Restitution"
On Error GoTo 0
With Sheets("Restitution").Cells(1)
.Resize(, 7) = Array("Référence", "Type", "Nom F1", "Nom F2", "Stock F1", "Stock F2", "Total")
.Offset(1).Resize(dico.Count, 7).Value = Application.Index(dico.items, 0, 0)
With .CurrentRegion
.VerticalAlignment = xlCenter
.Font.Name = "calibri"
.Font.Size = 10
.BorderAround Weight:=xlThin
.Borders(xlInsideVertical).Weight = xlThin
With .Rows(1)
.Interior.ColorIndex = 43
.HorizontalAlignment = xlCenter
.BorderAround Weight:=xlThin
.Font.Size = 11
End With
.Columns("a:d").HorizontalAlignment = xlCenter
'.Columns.AutoFit
End With
End With
Set dico = Nothing
Application.ScreenUpdating = True
End Sub
klin89