Insère un combobox dans ta page, n'importe où
Je passe en mode Développement > Création
J'insère ensuite un combobox
Mes données se trouvent ici :
Sheets("Nomenclature").Range("Tableau1[Libellé]").Value
à adapter : feuille Nomenclature, tableau Tableau1 et colonne Libellé
Je nomme la cellule qui sera le choix : ici Saisie que l'on retrouve ici
Intersect(Target, Range("Saisie"))
à adapter
Le code est le suivant :
Dim choix()
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("Saisie")) Is Nothing And Target.Count = 1 Then
choix = Sheets("Nomenclature").Range("Tableau1[Libellé]").Value
With Me.ComboBox1
.List = choix
.Height = Target.Height + 4
.Width = Target.Width
.Top = Target.Top - 2
.Left = Target.Left
.Value = Target
.Visible = True
.Activate
End With
Else
Me.ComboBox1.Visible = False
End If
End Sub
Private Sub ComboBox1_Change()
Set dico = CreateObject("Scripting.Dictionary")
For Each Item In choix
If UCase(Item) Like UCase(Me.ComboBox1) & "*" Then dico(Item) = ""
Next
Me.ComboBox1.List = dico.keys
Me.ComboBox1.DropDown
ActiveCell.Value = Me.ComboBox1
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
If IsError(Application.Match(ActiveCell, choix, 0)) Then ActiveCell = ""
ActiveCell.Offset(1).Select
End If
End Sub
inspiré de Jacques Boisgontier que je remercie (j'ai surtout introduit la notion de tableau)