Dim F1 As Worksheet, F2 As Worksheet 'mémorise les variables
Private Sub ChoixNom_Change()
ChoixPrenom = "": NomEnfant = ""
End Sub
Private Sub ChoixPrenom_Change()
NomEnfant = ""
End Sub
Private Sub ChoixPrenom_Enter()
If ChoixNom.ListIndex = -1 Then UserForm_Initialize: Exit Sub
Filtre "=A2=""" & ChoixNom & """", Union(F2.Columns(1), F2.Columns(3)), ChoixPrenom
End Sub
Private Sub NomEnfant_Enter()
If ChoixNom.ListIndex = -1 Then UserForm_Initialize: Exit Sub
If ChoixPrenom.ListIndex = -1 Then ChoixPrenom_Enter: Exit Sub
Filtre "=A2&CHAR(1)&B2=""" & ChoixNom & Chr(1) & ChoixPrenom & """", F2.Columns(1).Resize(, 2), NomEnfant
End Sub
Private Sub CommandButton1_Click() 'Quitter
Unload Me
End Sub
Private Sub UserForm_Initialize()
Set F1 = Sheets("Contact")
Set F2 = Sheets("A masquer")
Filtre "=TRUE", F2.Columns(2).Resize(, 2), ChoixNom
End Sub
Sub Filtre(critere$, ColSuppr As Range, CB As ComboBox)
F2.Cells.Clear 'RAZ
With F1.[A1].CurrentRegion.Resize(, 3)
.Cells(2, 5) = critere
.AdvancedFilter xlFilterCopy, .Cells(1, 5).Resize(2), F2.[A1] 'filtre avancé
.Cells(2, 5) = ""
End With
F2.Rows(1).Delete
ColSuppr.Delete
If Application.CountA(F2.Columns(1)) = 0 Then CB.Clear: Exit Sub
With F2.UsedRange
.Sort .Cells, xlAscending, Header:=xlNo 'tri alphabétique
.RemoveDuplicates 1, xlNo 'supprime les doublons
End With
CB.List = F2.UsedRange.Resize(, 2).Value 'au moins 2 éléments
CB.SetFocus
CB.DropDown 'déroule la liste
End Sub