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
| Sub Compare_Col_ABEFH_sur_Sheet1_et2()
Dim wbk As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim LastLig1 As Long, LastLig2 As Long, i As Long, k As Long
Dim c As Range, v As Range
Application.ScreenUpdating = False
Set wbk = ThisWorkbook
Set ws1 = wbk.Worksheets(1)
Set ws2 = wbk.Worksheets(2)
LastLig1 = ws1.Cells(Rows.Count, 1).End(xlUp).Row
LastLig2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row
Set ws3 = wbk.Worksheets.Add(After:=wbk.Sheets(wbk.Worksheets.Count))
'................................
For i = 1 To LastLig2
Set c = ws1.Range("A1:A" & LastLig1).Find(ws2.Range("A" & i).Value, lookat:=xlWhole)
If c Is Nothing Then
Set v = ws3.Columns(1).Find(ws2.Range("A" & i).Value, lookat:=xlWhole)
If v Is Nothing Then
k = k + 1
ws2.Range("A" & i & ":S" & i).Copy ws3.Range("A" & k)
End If
End If
Set v = Nothing
Next i
'................................
For i = 1 To LastLig2
Set c = ws1.Range("B1:B" & LastLig1).Find(ws2.Range("B" & i).Value, lookat:=xlWhole)
If c Is Nothing Then
Set v = ws3.Columns(1).Find(ws2.Range("B" & i).Value, lookat:=xlWhole)
If v Is Nothing Then
k = k + 1
ws2.Range("A" & i & ":S" & i).Copy ws3.Range("A" & k)
End If
End If
Set v = Nothing
Next i
'...................................
For i = 1 To LastLig2
Set c = ws1.Range("D1:D" & LastLig1).Find(ws2.Range("D" & i).Value, lookat:=xlWhole)
If c Is Nothing Then
Set v = ws3.Columns(1).Find(ws2.Range("D" & i).Value, lookat:=xlWhole)
If v Is Nothing Then
k = k + 1
ws2.Range("A" & i & ":S" & i).Copy ws3.Range("A" & k)
End If
End If
Set v = Nothing
Next i
'...................................
For i = 1 To LastLig2
Set c = ws1.Range("E1:E" & LastLig1).Find(ws2.Range("E" & i).Value, lookat:=xlWhole)
If c Is Nothing Then
Set v = ws3.Columns(1).Find(ws2.Range("E" & i).Value, lookat:=xlWhole)
If v Is Nothing Then
k = k + 1
ws2.Range("A" & i & ":S" & i).Copy ws3.Range("A" & k)
End If
End If
Set v = Nothing
Next i
'...................................
For i = 1 To LastLig2
Set c = ws1.Range("F1:F" & LastLig1).Find(ws2.Range("F" & i).Value, lookat:=xlWhole)
If c Is Nothing Then
Set v = ws3.Columns(1).Find(ws2.Range("F" & i).Value, lookat:=xlWhole)
If v Is Nothing Then
k = k + 1
ws2.Range("A" & i & ":S" & i).Copy ws3.Range("A" & k)
End If
End If
Set v = Nothing
Next i
'...................................
For i = 1 To LastLig2
Set c = ws1.Range("H1:H" & LastLig1).Find(ws2.Range("H" & i).Value, lookat:=xlWhole)
If c Is Nothing Then
Set v = ws3.Columns(1).Find(ws2.Range("H" & i).Value, lookat:=xlWhole)
If v Is Nothing Then
k = k + 1
ws2.Range("A" & i & ":S" & i).Copy ws3.Range("A" & k)
End If
End If
Set v = Nothing
Next i
'...................................
Set c = Nothing
Set ws3 = Nothing
Set ws2 = Nothing
Set ws1 = Nothing
Set wbk = Nothing
End Sub |
Partager