1er lettre dans une combobox

maval

XLDnaute Barbatruc
Bonjour,

J’ai sur un UserForm une ComboBox
J'aimerai que lorsque je tape la première lettre s’affiche uniquement les noms correspondants, c'est à dire ceux commençant par ces lettres.
La liste des noms se trouve dans la feuille nommé base de données " BD "

Je vous remercie de votre aide
 

Pièces jointes

  • 1er lettre combobox.xlsm
    62.1 KB · Affichages: 30

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
Re : 1er lettre dans une combobox

Bonjour,


Les moms apparaissent au fur et à mesure de la frappe des premières lettres(comme sur Google)

Voir Saisie intuitive formulaire

ComboBox.gif

JB
 

Pièces jointes

  • 1er lettre combobox.xls
    95 KB · Affichages: 63
Dernière édition:

maval

XLDnaute Barbatruc
Re : 1er lettre dans une combobox

Bonjour JB

Merci beaucoup pour le code, j'ai un petit souci j'ai voulu adapter ton code avec le mien mais sa me donne un message d'erreur "Objet requis" Voici mon code:

Code:
Private Sub ComboBox1_Change()

Dim Pays$, Indice&

On Error Resume Next
If ComboBox1.ListIndex > -1 Then
    Pays = ComboBox1.Value
    Indice = ComboBox1.ListIndex
    TextBox1.Value = Sheets("BD").Cells(Indice + 2, 4).Value
    Call ListeFichier(Pays)
End If
'-----------
Call EffacementImage
Call affichage_Image(Pays)
End Sub

'Le code ajouter

  Set d1 = CreateObject("Scripting.Dictionary")
  tmp = UCase(Me.ComboBox1) & "*"
  For Each c In a
    If UCase(c) Like tmp Then d1(c) = ""
  Next c
  Me.ComboBox1.List = d1.keys
  Me.ComboBox1.DropDown

Peut-on le modifier?

Merci d'avance et bonne journée
 

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
Re : 1er lettre dans une combobox

Bonjour,

voir PJ

Code:
Dim a(), répertoirePhoto
Private Sub UserForm_Initialize()
  a = [pays].Value
  Me.ComboBox1.List = a
  SendKeys "{F4}"
End Sub

Private Sub ComboBox1_Change()
   If Me.ComboBox1.ListIndex = -1 Then
   Dim b()
   tmp = Trim(UCase(Me.ComboBox1)) & "*"
   j = 0
   For i = LBound(a) To UBound(a)
    If Trim(UCase(a(i, 1))) Like tmp Then
      j = j + 1: ReDim Preserve b(1 To 2, 1 To j)
      b(1, j) = a(i, 1): b(2, j) = a(i, 2)
    End If
   Next i
   If j > 0 Then
      If UBound(b, 2) > 1 Then
        Me.ComboBox1.List = Application.Transpose(b)
      Else
        Dim c(1 To 1, 1 To 2)
        c(1, 1) = b(1, 1): c(1, 2) = b(2, 1)
        Me.ComboBox1.List = c
      End If
      Me.ComboBox1.DropDown
   End If
  Else
    Me.TextBox1 = Me.ComboBox1.Column(1)
    répertoirePhoto = "c:\dossier_flag\"
    nf = répertoirePhoto & Trim(Me.ComboBox1) & ".jpg"
    If Dir(nf) <> "" Then Me.Image1.Picture = LoadPicture(nf) Else Me.Image1.Picture = LoadPicture
  End If
End Sub

Private Sub CommandButton1_Click()
  [A2] = Me.ComboBox1.Column(0)
  [B2] = Me.ComboBox1.Column(1)
  nom = "monimage"
  On Error Resume Next
  ActiveSheet.Shapes(nom).Delete
  ActiveSheet.Pictures.Insert(répertoirePhoto & Me.ComboBox1 & ".jpg").Name = nom
  ActiveSheet.Shapes(nom).Left = [a4].Left
  ActiveSheet.Shapes(nom).Top = [a4].Top
  On Error GoTo 0
  Unload Me
End Sub

http://boisgontierjacques.free.fr/fichiers/DonneesValidation/FormIntuitif2colonnesPays.xls

Saisie.gif
SaisieIntuitive.gif

JB
 

Pièces jointes

  • FormIntuitif2colonnesPays.xls
    176.5 KB · Affichages: 54
  • SaisieIntuitive.gif
    SaisieIntuitive.gif
    21.7 KB · Affichages: 33
  • SaisieIntuitive.gif
    SaisieIntuitive.gif
    21.7 KB · Affichages: 33
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
311 725
Messages
2 081 940
Membres
101 845
dernier inscrit
annesof