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
| Sub test()
Dim wbA As Workbook, wbB As Workbook
Dim ShA As Worksheet, shB As Worksheet
Dim nbligA As Long, nbligB As Long, i As Long
Dim fileB As Variant
Dim c As Range
Application.ScreenUpdating = False
Set wbA = ThisWorkbook
Set ShA = wbA.Worksheets("A")
nbligA = ShA.Cells(ShA.Rows.Count, "C").End(xlUp).Row
fileB = Application.GetOpenFilename()
If fileB <> False Then
Set wbB = Workbooks.Open(fileB)
On Error GoTo Erreur
Set shB = wbB.Worksheets("A")
nbligB = shB.Cells(shB.Rows.Count, "C").End(xlUp).Row
For i = 2 To nbligB
Set c = ShA.Range("C2:C" & nbligA).Find(shB.Cells(i, "C").Value, LookIn:=xlValues, lookat:=xlWhole)
If c Is Nothing Then
nbligA = nbligA + 1
shB.Rows(i).Copy ShA.Range("A" & nbligA)
End If
Next i
Set c = Nothing
wbB.Close False
Erreur:
Set wbB = Nothing
Set shB = Nothing
End If
Set wbA = Nothing
Set ShA = Nothing
End Sub |
Partager