Private Sub Worksheet_Activate()
Worksheet_SelectionChange ActiveCell 'lance la macro quand on revient sur cette feuille
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim crit$, P As Range
Application.ScreenUpdating = False
Me.Unprotect "jlejle"
With Range("C27:C" & Rows.Count)
.Validation.Delete 'RAZ
If Intersect(ActiveCell, .Cells) Is Nothing Then GoTo 1
crit = ActiveCell(1, 0)
If crit = "" Then crit = "*"
With Sheets("liste articles").ListObjects(1).Range 'tableau structuré
.AutoFilter 'désactive le filtrage s'il existe
.Columns(5).Clear 'RAZ
.AutoFilter 3, crit 'filtrage de la 3ème colonne
Set P = .Columns(2).Offset(1).SpecialCells(xlCellTypeVisible)
.AutoFilter 'désactive le filtrage s'il existe
P.Copy .Cells(1, 5) 'copier-coller
.Columns(5).Sort .Columns(5), xlAscending, Header:=xlNo 'tri alphabétique
.Cells(1, 5).CurrentRegion.RemoveDuplicates 1, Header:=xlNo 'supprime les doublons
.Cells(1, 5).CurrentRegion.Name = "Liste" 'plage nommée
ActiveCell.Validation.Add xlValidateList, Formula1:="=Liste"
End With
End With
1 Me.Protect "jlejle"
End Sub