Sub RechercheCompatibilité()
'---> on suppose que les données sont déjà triées par "Lieux"
'Effacement anciennes données
LigFin = Range("A65536").End(xlUp).Row
Range(Cells(2, 5), Cells(LigFin, 6)).ClearContents
'Vérification des compatibilités
ErrTst = 0
For Lig = 2 To LigFin
Serrure = Cells(Lig, 1).Value
Lieu = Cells(Lig, 3).Value
LieuSecours = Cells(Lig, 4).Value
'--------- Vérification pour les Lieux --------------
'Vérification des clefs compatibles
For LigB = 2 To LigFin
If Lieu = Cells(LigB, 3).Value Then
'If LieuSecours = Cells(LigB, 4).Value Then
If LigB <> Lig Then
SerrureB = Cells(LigB, 13).Value
y = 1
Do
x = InStr(y, SerrureB, ",")
If x = 0 Then
SerrureBis = Right(SerrureB, 3)
Else
SerrureBis = Mid(SerrureB, y, x - y)
End If
If Serrure = SerrureBis Then
Cells(LigB, 5).Value = "'" & Cells(LigB, 5).Value & " " & SerrureBis & " (" & Cells(Lig, 2) & ")"
ErrTst = 1
End If
y = x + 2
Loop Until x = 0
End If
End If
Next LigB
'Vérification des serrures compatibles
For LigB = 2 To LigFin
If Lieu = Cells(LigB, 3).Value Then
'If LieuSecours = Cells(LigB, 4).Value Then
If LigB <> Lig Then
SerrureB = Cells(LigB, 14).Value
y = 1
Do
x = InStr(y, SerrureB, ",")
If x = 0 Then
SerrureBis = Right(SerrureB, 3)
Else
SerrureBis = Mid(SerrureB, y, x - y)
End If
If Serrure = SerrureBis Then
Cells(LigB, 6).Value = "'" & Cells(LigB, 6).Value & " " & SerrureBis & " (" & Cells(Lig, 2) & ")"
ErrTst = 1
End If
y = x + 2
Loop Until x = 0
End If
End If
Next LigB
'--------- Vérification pour les Lieux de Secours --------------
'Vérification des clefs compatibles
For LigB = 2 To LigFin
If LieuSecours = Cells(LigB, 4).Value Then
If LigB <> Lig Then
SerrureB = Cells(LigB, 13).Value
y = 1
Do
x = InStr(y, SerrureB, ",")
If x = 0 Then
SerrureBis = Right(SerrureB, 3)
Else
SerrureBis = Mid(SerrureB, y, x - y)
End If
If Serrure = SerrureBis Then
Cells(LigB, 5).Value = "'" & Cells(LigB, 5).Value & " " & SerrureBis & " (" & Cells(Lig, 2) & ")"
ErrTst = 1
End If
y = x + 2
Loop Until x = 0
End If
End If
Next LigB
'Vérification des serrures compatibles
For LigB = 2 To LigFin
If LieuSecours = Cells(LigB, 4).Value Then
If LigB <> Lig Then
SerrureB = Cells(LigB, 14).Value
y = 1
Do
x = InStr(y, SerrureB, ",")
If x = 0 Then
SerrureBis = Right(SerrureB, 3)
Else
SerrureBis = Mid(SerrureB, y, x - y)
End If
If Serrure = SerrureBis Then
Cells(LigB, 6).Value = "'" & Cells(LigB, 6).Value & " " & SerrureBis & " (" & Cells(Lig, 2) & ")"
ErrTst = 1
End If
y = x + 2
Loop Until x = 0
End If
End If
Next LigB
Next Lig
If ErrTst = 0 Then MsgBox ("OK pour comparaison avec les clefs et serrures compatibles")
End Sub