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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
Sub Comparaison()
'****************************** Déclaration des variables **********************************
Dim i As Integer
Dim j As Integer
Dim z As Integer
Dim Feuil1 As String
Dim Feuil2 As String
Dim ta(100) As String
Dim temp As Integer
Dim l As Integer
Application.ScreenUpdating = False
UserForm1.Show vbModeless
UserForm1.Visible
Windows("Comparaison des fichiers PARCS.xls").Activate
Sheets("Mode d'emploi").Select
Feuil1 = Range("m2")
Feuil2 = Range("n2")
'****************************** Vidage des couleurs en place et suppression contenu de la
'*******************************colonne bk
Sheets(Feuil1).Select
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Cells.Select
Range("B1").Activate
Selection.Interior.ColorIndex = xlNone
Sheets(Feuil2).Select
Cells.Select
Range("B1").Activate
Selection.Interior.ColorIndex = xlNone
Columns("bo:bo").Select
Selection.ClearContents
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'****************************** Début boucle sur la 1er feuille *****************************
temp = 1
For i = 2 To 25000
Sheets(Feuil1).Select
UserForm1.abelProgress.Value = i / 2500 * 10
UserForm1.Pourcentage.Caption = i / 2500 * 10 & "%"
UserForm1.Repaint
'****************************** Teste fin de feuil1 *****************************************
If Range("a" & i) = "" Then
i = 25001
End
Else
'****************************** Copie de la ligne de la feuil1 dans ta **********************
For j = 1 To 67
ta(j) = Cells(i, j)
Next j
'****************************** Début boucle sur 2ème feuille *******************************
Sheets(Feuil2).Select
For j = 2 To 25000
'****************************** Teste fin de feuil2 *****************************************
If Range("a" & j) = "" Then
j = 25001
Else
'****************************** PI trouvé ***************************************************
If Range("a" & j) = ta(1) Then
flag = 0
l = 2
'****************************** Parcours de la ligne ****************************************
For z = 2 To 100
'****************************** Différence entre cellule feuil1 et cellule feuil2 ***********
If Not Cells(j, z) = ta(z) Then
'****************************** Coloriage en orange *****************************************
Cells(j, z).Select
With Selection.Interior
.ColorIndex = 45
.Pattern = xlSolid
End With
l = l + 1
flag = 1
End If
Next
'****************************** Si les lignes sont bien conformes met "Ok" et colorie en vert
'dans la colonne K et l'indice de la ligne (à modifier selon besoin) sinon "Erreur" et en rouge
If flag = 1 Then
Range("bo" & j) = "modification"
Range("bo" & j).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Else
Range("bo" & j) = "Ok"
Range("bo" & j).Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End If
j = 25000
End If
End If
Next
'****************************** Sortie de la boucle sans trouvé de PI dans la feuil2 ********
If j = 25002 Then
If temp = 1 Then
Sheets.Add
ActiveSheet.Select
ActiveSheet.Name = "Temp"
End If
Sheets(Feuil1).Select
Rows(i).Select
Selection.Copy
Sheets("temp").Select
Range("a" & temp).Select
ActiveSheet.Paste
temp = temp + 1
End If
End If
Next
Application.ScreenUpdating = True
End Sub
Sub UpdateProgressBar(PctDone As Single)
With UserForm1
' Update the Caption property of the Frame control.
.FrameProgress.Caption = Format(PctDone, "0%")
' Widen the Label control.
.LabelProgress.Width = PctDone * _
(.FrameProgress.Width - 10)
End With
' The DoEvents allows the UserForm to update.
DoEvents
End Sub |
Partager