Option Explicit
Sub test()
Dim a, i As Long, j As Long, n As Long, w(), e
a = Sheets("Feuil1").Range("a1").CurrentRegion.Value 'STT1
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(a, 1)
ReDim w(1 To 8)
For j = 1 To UBound(a, 2)
w(j) = a(i, j)
Next
.Item(a(i, 1)) = w
Next
a = Sheets("Feuil2").Range("a1").CurrentRegion.Value 'STT2
For i = 2 To UBound(a, 1)
w = .Item(a(i, 1))
w(7) = a(i, 2)
w(8) = w(7) - w(2)
.Item(a(i, 1)) = w
Next
ReDim a(1 To .Count, 1 To 8)
For Each e In .keys
If .Item(e)(8) <> 0 Then
n = n + 1
For j = 1 To UBound(.Item(e))
a(n, j) = .Item(e)(j)
Next
End If
Next
End With
If n > 0 Then
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Resultat").Delete
Application.DisplayAlerts = True
On Error GoTo 0
Sheets.Add.Name = "Resultat"
With Sheets("Resultat").Cells(1)
.Resize(1, UBound(a, 2)).Value = Array("Référence", "Montant", _
"Code 1", "Code 2", "Nom", "Date", "Montant STT2", "Ecart")
.Offset(1).Resize(n, UBound(a, 2)).Value = a
With .CurrentRegion
.Font.Name = "calibri"
.BorderAround Weight:=xlThin
.Borders(xlInsideVertical).Weight = xlThin
.VerticalAlignment = xlCenter
With .Rows(1)
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 40
.Font.Bold = True
.BorderAround Weight:=xlThin
End With
'.Columns.AutoFit
End With
End With
Application.ScreenUpdating = True
Else
MsgBox "Aucune donnée"
End If
End Sub