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
| Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim f1 As Worksheet, f2 As Worksheet
Dim DerLig_f1 As Long, DerLig_f2 As Long
Application.ScreenUpdating = False
Application.EnableEvents = False
Set f1 = Sheets("Planning")
Set f2 = Sheets("Liste des bus")
If Not Intersect(Target, Range("C2:E100")) Is Nothing Then
DerLig_f1 = f1.[B10000].End(xlUp).Row
Set Bus = f1.Range("B1:B" & DerLig_f1).Find(Target, LookIn:=xlValues, lookat:=xlWhole)
If Not Bus Is Nothing Then
f1.Range(Cells(Bus.Row, "A"), Cells(Bus.Row, "B")).Delete Shift:=xlUp
Else 'on reconstruit la liste des bus et on ne conserve que les bus non sélectionnés en B, C ou D
DerLig_f2 = f2.[B10000].End(xlUp).Row
f2.Range("A1:B" & DerLig_f2).Copy Destination:=f1.[A1]
For Each Cell In f1.Range("C2:E" & DerLig_f2)
If Cell <> "" Then
Set Bus = f1.Range("B1:B" & DerLig_f2).Find(Cell, LookIn:=xlValues, lookat:=xlWhole)
If Not Bus Is Nothing Then f1.Range(Cells(Bus.Row, "A"), Cells(Bus.Row, "B")).Delete Shift:=xlUp
End If
Next
End If
End If
Application.EnableEvents = True
Set Bus = Nothing
Set f1 = Nothing
Set f2 = Nothing
End Sub |
Partager