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
| Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim C As Range, BD1 As Workbook, BD2 As Workbook, FL As Worksheet, Ref As String, Lig As Byte
Dim Verif1 As Integer, Verif2 As Integer, Result1 As String, Result2 As String, adresse1 As String
If Target.Count > 1 Or Application.Intersect(Target, Range("B13:B32")) Is Nothing Or Target.Value = "" Then Exit Sub
Ref = Target.Value
Lig = Target.Row
Set BD1 = Workbooks("Base de données 1.xlsx")
Set BD2 = Workbooks("Base de données 2.xlsx")
For Each FL In BD1.Worksheets
Set C = FL.Range("A:A").Find(what:=Ref, lookat:=xlWhole)
If Not C Is Nothing Then
adresse1 = C.Address
Verif1 = 1
Result1 = "feuille " & FL.Name & " / cellule " & C.Address(0, 0)
Cells(Lig, 1) = FL.Cells(C.Row, 2)
Cells(Lig, 3) = FL.Cells(C.Row, 3)
Cells(Lig, 4) = FL.Cells(C.Row, 4)
Cells(Lig, 5) = FL.Cells(C.Row, 5)
Do Until C Is Nothing
Set C = FL.Range("A:A").FindNext(C)
If Not C Is Nothing And C.Address <> adresse1 Then
Verif1 = Verif1 + 1
Result1 = "feuille " & FL.Name & " / cellule " & C.Address(0, 0)
Else
Set C = Nothing
End If
Loop
End If
Next
For Each FL In BD2.Worksheets
Set C = FL.Range("A:A").Find(what:=Ref, lookat:=xlWhole)
If Not C Is Nothing Then
adresse1 = C.Address
Verif2 = 1
Result2 = "feuille " & FL.Name & " / cellule " & C.Address(0, 0)
Cells(Lig, 6) = FL.Cells(C.Row, 2)
Cells(Lig, 7) = FL.Cells(C.Row, 3)
Cells(Lig, 8) = FL.Cells(C.Row, 4)
Do Until C Is Nothing
Set C = FL.Range("A:A").FindNext(C)
If Not C Is Nothing And C.Address <> adresse1 Then
Verif2 = Verif2 + 1
Result2 = "feuille " & FL.Name & " / cellule " & C.Address(0, 0)
Else
Set C = Nothing
End If
Loop
End If
Next
If Verif1 > 1 Then
MsgBox "La référence " & Ref & " a été trouvée " & Verif1 & " fois dans le classeur " & BD1.Name & Chr(10) & Result1
End If
If Verif2 > 1 Then
MsgBox "La référence " & Ref & " a été trouvée " & Verif2 & " fois dans le classeur " & BD2.Name & Chr(10) & Result2
End If
Set BD1 = Nothing
Set BD2 = Nothing
End Sub |