Sub Compare()
Dim fichier1$, fichier2$, wb1 As Workbook, wb2 As Workbook, tablo1, tablo2, ub&, i&, x, y, j&, resu(), n&
fichier1 = "Fichier N.xlsx" 'à adapter
fichier2 = "Fichier N+1.xlsx" 'à adapter
On Error Resume Next
Set wb1 = Workbooks(fichier1)
If wb1 Is Nothing Then MsgBox "Ouvrez '" & fichier1 & "'...": Exit Sub
Set wb2 = Workbooks(fichier2)
If wb2 Is Nothing Then MsgBox "Ouvrez '" & fichier2 & "'...": Exit Sub
tablo1 = wb1.Sheets(1).[A1].CurrentRegion.Resize(, 3) 'matrice, plus rapide
ub = UBound(tablo1)
tablo2 = wb2.Sheets(1).[A1].CurrentRegion.Resize(, 3) 'matrice, plus rapide
For i = 1 To UBound(tablo2)
If tablo2(i, 3) <> Chr(1) Then
x = tablo2(i, 1): y = tablo2(i, 2)
For j = 1 To ub
If tablo1(j, 1) = x And tablo1(j, 2) = y And tablo1(j, 3) <> Chr(1) Then
tablo1(j, 3) = Chr(1) 'repère
tablo2(i, 3) = Chr(1) 'repère
Exit For
End If
Next j
End If
Next i
'---tableau des résultats---
ReDim resu(1 To UBound(tablo2), 1 To 3)
For i = 1 To UBound(tablo2)
If tablo2(i, 3) <> Chr(1) Then
n = n + 1
resu(n, 1) = i
resu(n, 2) = tablo2(i, 1)
resu(n, 3) = tablo2(i, 2)
End If
Next i
'---restitution---
With ThisWorkbook.ActiveSheet 'adapter au besoin
.Activate
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
With .[A2] '1ère cellule de destination
If n Then .Resize(n, 3) = resu
.Offset(n).Resize(Rows.Count - n - .Row + 1, 3).ClearContents 'RAZ en dessous
.Resize(, 3).EntireColumn.AutoFit 'ajuste les largeurs
End With
With .UsedRange: End With 'actualise la barre de défilement verticale
End With
End Sub