Bonjour,
A tester.
Cdlt.
Option Explicit
Option Private Module
Public Sub Calcul_ecarts()
'Quantité Physique - Quantité Papier
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim monDico As Object
Dim c As Range
Application.ScreenUpdating = False
Set ws1 = Worksheets("Quantité papier")
Set ws2 = Worksheets("Quantité Physique")
Set ws3 = Worksheets("Ecart")
Set monDico = CreateObject("Scripting.Dictionary")
' - quantité papier
With ws1
For Each c In .Range("C2", .[C1048576].End(xlUp))
monDico(c.Value) = monDico(c.Value) - c.Offset(, 1).Value
Next c
End With
' + quantité physique
With ws2
For Each c In .Range("C2", .[C1048576].End(xlUp))
monDico(c.Value) = monDico(c.Value) + c.Offset(, 1).Value
Next c
End With
With ws3
.[A1].CurrentRegion.Offset(1, 0).Delete
.[A2].Resize(monDico.Count, 1) = Application.Transpose(monDico.keys)
.[B2].Resize(monDico.Count, 1) = Application.Transpose(monDico.items)
.[A1].Sort Key1:=.[A2], Order1:=xlAscending, Header:=xlYes
.Activate
.[A1].Select
End With
Set monDico = Nothing
Set ws1 = Nothing: Set ws2 = Nothing: Set ws3 = Nothing
End Sub