besoin d'aide dans userform

revemane

XLDnaute Nouveau
[Résolu] besoin d'aide dans userform

bonjour,
je souhaite faire ceci et je bloque

j'ai un userform pour lequel j'ai une liste déroulante qui me permet d'afficher les nom de client dans des txtbox du formulaire

la cobobox va chercher les information dans la feuille (client)

je souhaite inclure a mon userform une listebox sur 4 collones qui m'afficherai les transaction du client pour lequel les donnée sont stockées dans la feuille (BD)
la feuille bd contient 5 colonnes

n° de transaction - nom - prenom - montant ttc - date

j'ai besoin que ma liste comprenne non, prenom, montant ttc,date

je n'y arrive pas

j'ai bien trouvé ceci mais j'arrive pas à l'adapter à ce que j'ai besoin

Private Sub B_go_Click()
Me.ListBox1.Clear
Set c = Range("a:a").Find(Me.TextBox1.Value, LookIn:=xlValues)
If Not c Is Nothing Then
premier = c.Address
i = 0
Do
Me.ListBox1.AddItem
Me.ListBox1.List(i, 0) = c.Value
Me.ListBox1.List(i, 1) = c.Offset(0, 1).Value
Me.ListBox1.List(i, 2) = c.Offset(0, 2).Value
Set c = Range("a:a").FindNext(c)
i = i + 1
Loop While Not c Is Nothing And c.Address <> premier
End If
End Sub

merci de m'aider jespere avoir ete asser claire
 
Dernière édition:

bqtr

XLDnaute Accro
Re : besoin d'aide dans userform

Bonsoir,

Essaye ceci :

Code:
Private Sub B_GO_Click_Click()

Dim c As Range, premier As String, i As Long

With ListBox1
  .Clear
  .ColumnCount = 4
  .TextAlign = fmTextAlignRight
End With

With Range("a1:a" & Range("a65536").End(xlUp).Row)
   Set c = .Find(Me.TextBox1.Value, LookIn:=xlValues)
   If Not c Is Nothing Then
       premier = c.Address
       Do
          Me.ListBox1.AddItem c.Value
          Me.ListBox1.Column(1, i) = c.Offset(0, 1).Value
          Me.ListBox1.Column(2, i) = Format(c.Offset(0, 2).Value, "# ##0.00")
          Me.ListBox1.Column(3, i) = Format(c.Offset(0, 3).Value, "dd/mm/yyyy")
          Set c = .FindNext(c)
          i = i + 1
       Loop While Not c Is Nothing And c.Address <> premier
   End If
End With

End Sub

Bonne soirée
 

revemane

XLDnaute Nouveau
Re : besoin d'aide dans userform

Bonsoir,

Essaye ceci :

Code:
Private Sub B_GO_Click_Click()

Dim c As Range, premier As String, i As Long

With ListBox1
  .Clear
  .ColumnCount = 4
  .TextAlign = fmTextAlignRight
End With

With Range("a1:a" & Range("a65536").End(xlUp).Row)
   Set c = .Find(Me.TextBox1.Value, LookIn:=xlValues)
   If Not c Is Nothing Then
       premier = c.Address
       Do
          Me.ListBox1.AddItem c.Value
          Me.ListBox1.Column(1, i) = c.Offset(0, 1).Value
          Me.ListBox1.Column(2, i) = Format(c.Offset(0, 2).Value, "# ##0.00")
          Me.ListBox1.Column(3, i) = Format(c.Offset(0, 3).Value, "dd/mm/yyyy")
          Set c = .FindNext(c)
          i = i + 1
       Loop While Not c Is Nothing And c.Address <> premier
   End If
End With

End Sub

Bonne soirée

merci cela fonctionne mais y a t'il la possibilité de le faire avec un combobox qui selectionne le nom de la personne et que les donnée apparaissent dans la liste box sans passer par une zone txt ou l'on doit taper le non et puis cliquer sur le bouton

merci
 

bqtr

XLDnaute Accro
Re : besoin d'aide dans userform

Re,

Teste ceci:

Code:
Private Sub ComboBox1_Click()

Dim c As Range, premier As String, i As Long

ListBox1.Clear

With Range("a1:a" & Range("a65536").End(xlUp).Row)
   Set c = .Find(Me.ComboBox1.Value, LookIn:=xlValues)
   If Not c Is Nothing Then
       premier = c.Address
       Do
          Me.ListBox1.AddItem c.Value
          Me.ListBox1.Column(1, i) = c.Offset(0, 1).Value
          Me.ListBox1.Column(2, i) = Format(c.Offset(0, 2).Value, "# ##0.00")
          Me.ListBox1.Column(3, i) = Format(c.Offset(0, 3).Value, "dd/mm/yyyy")
          Set c = .FindNext(c)
          i = i + 1
       Loop While Not c Is Nothing And c.Address <> premier
   End If
End With

End Sub


Private Sub UserForm_Initialize()

Dim k As Long

With Sheets("Feuil5")
  For k = 1 To .Range("A65536").End(xlUp).Row
    ComboBox1 = .Range("A" & k)
    If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem .Range("A" & k)
  Next k
End With

With ListBox1
  .Clear
  .ColumnCount = 4
  .TextAlign = fmTextAlignRight
End With

ComboBox1.ListIndex = -1

End Sub

Dans la macro Private Sub UserForm_Initialize(), il faut adapté le nom de la feuille.
Tu sélectionnes un nom dans le combobox et cela rempli la Listbox, plus besoin du bouton GO.

A+
 

revemane

XLDnaute Nouveau
Re : besoin d'aide dans userform

Re,

Teste ceci:

Code:
Private Sub ComboBox1_Click()

Dim c As Range, premier As String, i As Long

ListBox1.Clear

With Range("a1:a" & Range("a65536").End(xlUp).Row)
   Set c = .Find(Me.ComboBox1.Value, LookIn:=xlValues)
   If Not c Is Nothing Then
       premier = c.Address
       Do
          Me.ListBox1.AddItem c.Value
          Me.ListBox1.Column(1, i) = c.Offset(0, 1).Value
          Me.ListBox1.Column(2, i) = Format(c.Offset(0, 2).Value, "# ##0.00")
          Me.ListBox1.Column(3, i) = Format(c.Offset(0, 3).Value, "dd/mm/yyyy")
          Set c = .FindNext(c)
          i = i + 1
       Loop While Not c Is Nothing And c.Address <> premier
   End If
End With

End Sub


Private Sub UserForm_Initialize()

Dim k As Long

With Sheets("Feuil5")
  For k = 1 To .Range("A65536").End(xlUp).Row
    ComboBox1 = .Range("A" & k)
    If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem .Range("A" & k)
  Next k
End With

With ListBox1
  .Clear
  .ColumnCount = 4
  .TextAlign = fmTextAlignRight
End With

ComboBox1.ListIndex = -1

End Sub

Dans la macro Private Sub UserForm_Initialize(), il faut adapté le nom de la feuille.
Tu sélectionnes un nom dans le combobox et cela rempli la Listbox, plus besoin du bouton GO.

A+


merci cela fonctionne mais il y a quand meme un probleme

voici mon code que j'ai modifier d'apres le tient
Private Sub ComboBox1_Click()

Dim c As Range, premier As String, i As Long

ListBox1.Clear

With Range("b1:b" & Range("b65536").End(xlUp).Row)
Set c = .Find(Me.ComboBox1.Value, LookIn:=xlValues)
If Not c Is Nothing Then
premier = c.Address
Do
Me.ListBox1.AddItem c.Value
Me.ListBox1.Column(1, i) = c.Offset(0, 1).Value
Me.ListBox1.Column(2, i) = Format(c.Offset(0, 2).Value, "# ##0.00")
Me.ListBox1.Column(3, i) = Format(c.Offset(0, 3).Value, "dd/mm/yyyy")
Set c = .FindNext(c)
i = i + 1
Loop While Not c Is Nothing And c.Address <> premier
End If
End With

End Sub


Private Sub UserForm_Initialize()

Dim k As Long

With Sheets("BD")
For k = 2 To .Range("B65536").End(xlUp).Row
ComboBox1 = .Range("B" & k)
If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem .Range("B" & k)
Next k
End With

With ListBox1
.Clear
.ColumnCount = 4
.TextAlign = fmTextAlignLeft
End With

ComboBox1.ListIndex = -1

End Sub



pour que cela fonctionne il faut que la feuille BD soit active dans Excel sinon si je suis dans ne autre feuille (menu par exemple et que je lance le formulaire dans la combobox j'ai bien les nom qui apparaissent et quand je le sélectionne j'ai rien qui apparrait dans la listbox
peux tu m'aider svp
merci
 

bqtr

XLDnaute Accro
Re : besoin d'aide dans userform

Re,

Si tu ne travailles pas avec la feuille active (Feuille BD) il faut indiquer au code où prendre les données.
Pour la macro : Private Sub ComboBox1_Click(), il faut renseigner la feuille où la recherche se fait comme ceci:

Code:
Private Sub ComboBox1_Click()

Dim c As Range, premier As String, i As Long

ListBox1.Clear

With Sheets("[B]BD[/B]").Range("a1:a" & Sheets("[B]BD[/B]").Range("a65536").End(xlUp).Row)
   Set c = .Find(Me.ComboBox1.Value, LookIn:=xlValues)
'.../...

Ainsi tu pourras utiliser le combobox quelque soit la feuille active.

A+
 

Discussions similaires

Réponses
7
Affichages
579

Statistiques des forums

Discussions
312 489
Messages
2 088 855
Membres
103 976
dernier inscrit
kaizertv2001@gmailcom