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
| Sub testtt()
Application.ScreenUpdating = False
Dim f1 As Worksheet
Dim f2 As Worksheet
Dim f3 As Worksheet
Set f1 = Sheets("f1")
Set f2 = Sheets("f2")
Set f3 = Sheets("Résultat")
Dim TblBD1
Dim TblBD2
Dim i As Integer
Dim j As Integer
Dim Lig As Long
Dim Identique As Boolean
Dim ProbQuantite As Boolean
Dim inexistantF2 As Boolean
Dim inexistantF1 As Boolean
f3.Cells.ClearContents
f3.Cells(1, 1) = f1.Cells(1, 1)
f3.Cells(1, 2) = f1.Cells(1, 2)
f3.Cells(1, 3) = "Remarques"
TblBD1 = f1.Range("A2:B" & f1.Range("A" & Rows.Count).End(xlUp).Row)
TblBD2 = f2.Range("A2:B" & f2.Range("A" & Rows.Count).End(xlUp).Row)
Lig = 2
For i = LBound(TblBD1) To UBound(TblBD1)
Identique = False
ProbQuantite = False
inexistantF2 = False
inexistantF1 = False
'*************************************Article identique *********************************
For j = LBound(TblBD2) To UBound(TblBD2)
If TblBD2(j, 1) = TblBD1(i, 1) And TblBD2(j, 2) = TblBD1(i, 2) Then
Identique = True
Exit For
End If
Next j
If Identique = True Then
With f3
.Cells(Lig, 1) = TblBD2(j, 1)
.Cells(Lig, 2) = TblBD2(j, 2)
.Cells(Lig, 3) = "Article identique sur les deux tableaux"
End With
Lig = Lig + 1
End If
'*************************************Problème Quantité *********************************
For j = LBound(TblBD2) To UBound(TblBD2)
If TblBD2(j, 1) = TblBD1(i, 1) And TblBD2(j, 2) <> TblBD1(i, 2) Then
ProbQuantite = True
Exit For
End If
Next j
If ProbQuantite = True Then
With f3
.Cells(Lig, 1) = TblBD2(j, 1)
.Cells(Lig, 2) = TblBD2(j, 2)
.Cells(Lig, 3) = "Article existant mais problème de quantité"
End With
Lig = Lig + 1
End If
Next i
'*************************************Existe en F1 et non pas en F2 *********************************
Dim plage1 As Range
Dim plage2 As Range
Dim Cel As Range
Dim dernligne As Long
Set plage1 = f1.Range("A2:A" & f1.Range("A" & Rows.Count).End(xlUp).Row)
Set plage2 = f2.Range("A2:A" & f2.Range("A" & Rows.Count).End(xlUp).Row)
For Each Cel In plage1
P = WorksheetFunction.CountIf(plage2, Cel.Value)
If P = 0 Then
dernligne = f3.Cells(Rows.Count, 1).End(xlUp).Row + 1
f3.Cells(dernligne, 1) = f1.Cells(Cel.Row, 1)
f3.Cells(dernligne, 2) = f1.Cells(Cel.Row, 2)
f3.Cells(dernligne, 3) = "Article existe en F1 et non en F2"
End If
Next Cel
'*************************************Existe en F2 et non pas en F1 *********************************
For Each Cel In plage2
C = WorksheetFunction.CountIf(plage1, Cel.Value)
If C = 0 Then
dernligne = f3.Cells(Rows.Count, 1).End(xlUp).Row + 1
f3.Cells(dernligne, 1) = f2.Cells(Cel.Row, 1)
f3.Cells(dernligne, 2) = f2.Cells(Cel.Row, 2)
f3.Cells(dernligne, 3) = "Article existe en F2 et non en F1"
End If
Next Cel
MsgBox ("Controle effectué")
f3.Select
Application.ScreenUpdating = True
f3.Select
End Sub |
Partager