1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| Sub Compare()
'Définit les 3 variables dont on a besoin
Dim EnrCol1(65000) As String
Dim EnrCol2(65000) As String
Dim Ligne As Integer
Dim papa As String, maman As String
Dim li As Long
Dim a As Long
Dim b As Long
Dim Pointeur3 As Long
Dim Pointeur4 As Long
Dim Pointeur5 As Long
Dim Correspondance As Boolean
'Définit le nombre de lignes actives dans les listes
Ligne = ActiveSheet.UsedRange.Rows.Count
For i = 1 To Ligne
'Crée une variable texte sans espace pour chaque colonne à comparer
papa = Replace(Cells(i, 1), " ", "")
maman = Replace(Cells(i, 2), " ", "")
'Ecrit les valeurs dans les nouvelles colonnes
Cells(i, 9) = papa
Cells(i, 10) = maman
SLB2 = Replace(Cells(i, 10), "/", "")
Cells(i, 11) = papa2
'Compare si les colonnes 1 et 2 sont différentes, et les copie dans une 3e colonne
'on met en mémoire les données de la colonne 9
a = 1
li = 1
Do Until li > Ligne
If Cells(li, 9).Value <> "" Then
EnrCol1(a) = Trim(Cells(li, 9).Value)
a = a + 1
End If
li = li + 1
Loop
'on met en mémoire les données de la colonne 11
a = 1
li = 1
Do Until li > Ligne
If Cells(li, 11).Value <> "" Then
EnrCol2(a) = Trim(Cells(li, 11).Value)
a = a + 1
End If
li = li + 1
Loop
Next
'on vérifie maintenant si les données de la colonne 1 sont dans la colonne 2
a = 1
Do Until a > Ligne
Correspondance = False
For b = 1 To Ligne
If UCase(EnrCol1(a)) = UCase(EnrCol2(b)) Then
Cells(Pointeur3, 6) = EnrCol1(a) 's'il y a correspondance ont met l'entrée dans la colonne 6
Pointeur3 = Pointeur3 + 1
Correspondance = True
b = Ligne
End If
Next b
If Correspondance = False Then
'########## ERREUR SUR LA LIGNE CI-DESSOUS ##########
Cells(Pointeur4, 4) = EnrCol1(a) 's'il n'y a pas correspondance on met les données dans la colonne 4
Pointeur4 = Pointeur4 + 1
End If
a = a + 1
Loop
'on vérifie maintenant si les données de la colonne 2 sont dans la colonne 1
a = 1
Do Until a > Ligne
Correspondance = False
For b = 1 To Ligne
If UCase(EnrCol2(a)) = UCase(EnrCol1(b)) Then
Correspondance = True
b = Ligne
End If
Next b
If Correspondance = False Then
Cells(Pointeur5, 5) = EnrCol2(a) 's'il n'y a pas correspondance on met les données dans la colonne 5
Pointeur5 = Pointeur5 + 1
End If
a = a + 1
Loop
'Mets en forme les colonnes
Cells(1, 6) = "papa&maman"
Cells(1, 5) = "papa"
Cells(1, 4) = "maman"
Cells(1, 9) = "int_papa"
Cells(1, 10) = "int_maman"
Cells(1, 11) = "int_maman2"
For i = 1 To 11
Columns(i).AutoFit
Next
End Sub |