Sub recap_skoobi()
'initialisation des variables
Dim tExist As Variant, tAcre As Variant, Dico As Object, tResult() As Variant, i As Long
Set Dico = CreateObject("Scripting.Dictionary")
'on met les données dans des tableaux VBA
With Sheets("EXISTANT")
tExist = .Range("A2", .Range("D65536").End(xlUp))
End With
With Sheets("A CREER")
tAcre = .Range("A2", .Range("D65536").End(xlUp))
End With
'on met chaque ligne colonne A à C du tableau "tExist" (feuille "EXISTANT") dans le "dictionnaire"
For i = LBound(tExist, 1) To UBound(tExist, 1)
Dico.Add tExist(i, 1) & "#" & tExist(i, 2) & "#" & tExist(i, 3), tExist(i, 1) & "#" & tExist(i, 2) & "#" & tExist(i, 3)
Next
'on transpose "tExist" pour pouvoir l'agrandir ensuite
tExist = Application.Transpose(tExist)
'on boucle dans le tableau "tAcre" (feuille "A CREER")
For i = LBound(tAcre, 1) To UBound(tAcre, 1)
'on vérifie que "la ligne" n'existe pas déjà dans le dictionnaire
If Not Dico.exists(tAcre(i, 1) & "#" & tAcre(i, 2) & "#" & tAcre(i, 3)) Then
'on agrandie "tExist"
ReDim Preserve tExist(1 To 4, 1 To UBound(tExist, 2) + 1)
'on ajoute la ligne dans "tExist"
tExist(1, UBound(tExist, 2)) = tAcre(i, 1)
tExist(2, UBound(tExist, 2)) = tAcre(i, 2)
tExist(3, UBound(tExist, 2)) = tAcre(i, 3)
tExist(4, UBound(tExist, 2)) = tAcre(i, 4)
End If
Next
With Sheets("RECAP")
'on vide la feuille
If .Range("A2").Value <> "" Then .Range("A2", .Range("D65536").End(xlUp)).Clear
'on copie le tableau "tExist" dans la feuille
.Range("A2", .Range("D" & UBound(tExist, 2) + 1)).Value = Application.Transpose(tExist)
End With
'reste plus qu'à faire le tri du résultat ;)
End Sub