Comment on peut faire compliqué quand il est possible de faire plus simple !! avec des outils standards ...
Private Sub Worksheet_Change(ByVal Target As Range)
' condiitons préalables
If Target.Count > 1 Then Exit Sub
If Target.Row <= 12 Then Exit Sub
' colonne assurance
If Not Intersect(Target, Columns("A")) Is Nothing Then
' effacement à droite et plus bas
dlg = Range("C" & Rows.Count).End(xlUp).Row
Rows(Target.Row + 1 & ":" & Application.Max(Target.Row + 1, dlg)).Delete
Target.Offset(0, 1).Resize(1, 4).ClearContents
' mise en place menu déroulant colonne B
Application.EnableEvents = False
Call prof
Application.EnableEvents = True
' colonne profession
ElseIf Not Intersect(Target, Columns("B")) Is Nothing Then
' effacement à droite et plus bas
dlg = Range("C" & Rows.Count).End(xlUp).Row
Rows(Target.Row + 1 & ":" & Application.Max(Target.Row + 1, dlg)).Delete
Target.Offset(0, 1).Resize(1, 3).ClearContents
' lancement du filtre
Application.EnableEvents = False
If Target.Offset(0, -1) <> "" Then filtre
Application.EnableEvents = True
End If
End Sub
Sub Supprime()
Dim dlg As Integer
With Sheets("Feuil1")
dlg = .Range("C" & Rows.Count).End(xlUp).Row + 1
.Rows("13:" & dlg).Delete
End With
Call assu
End Sub
Sub assu()
Dim data() As Variant
Dim dico As Object
With Sheets("Feuil1")
dlg = .Range("C" & Rows.Count).End(xlUp).Row + 1
data = [Assurances].Value
With .Cells(dlg, 1)
.ClearContents
.Validation.Delete
Set dico = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(data)
dico(data(i, 1)) = ""
Next
If dico.Count > 0 Then
.Validation.Delete
.Validation.Add xlValidateList, Formula1:=Join(dico.keys, ",")
End If
End With
With .Cells(dlg, 2)
.ClearContents
.Validation.Delete
End With
End With
End Sub
Sub prof()
Dim data() As Variant
Dim dico As Object
With Sheets("Feuil1")
dlg = .Range("A" & Rows.Count).End(xlUp).Row
crit = .Cells(dlg, 1)
data = Sheets("Feuil2").Cells(1, 1).CurrentRegion.Value
With .Cells(dlg, 2)
.ClearContents
.Validation.Delete
Set dico = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(data)
If data(i, 1) = crit Then dico(data(i, 2)) = ""
Next
If dico.Count > 0 Then
.Validation.Delete
.Validation.Add xlValidateList, Formula1:=Join(dico.keys, ",")
End If
End With
End With
End Sub
Sub filtre()
Dim data() As Variant
With Sheets("Feuil1")
data = Sheets("Feuil2").Cells(1, 1).CurrentRegion.Value
dlg = .Range("A" & Rows.Count).End(xlUp).Row
If .Cells(dlg, 2) = "" Then Exit Sub
ligne = dlg
For i = 2 To UBound(data)
If data(i, 1) = .Cells(dlg, 1) And data(i, 2) = .Cells(dlg, 2) Then
.Cells(ligne, 3) = data(i, 3)
.Cells(ligne, 4) = data(i, 4)
.Cells(ligne, 5) = data(i, 5)
ligne = ligne + 1
End If
Next
End With
Call assu
End Sub
J'ai presque honte de cela !