Filtre ListBox

Hello Les Experts, Le Forum,

Je remue le forum depuis hier et teste beaucoup de propositions mais rien ne va.... Ou alors je ne comprends pas, novice oblige !!!

Manip sûrement simple mais pas pour moi.

Dans l'USF, j'aimerais qu'une fois le "Client" rempli il ne reste dans la ListBox que des lignes concernant le Client.

Fichier prémâché ici :

53bandit-filtre.zip (13.48 Ko)

En vous remerciant déjà pour l'attention

Bandit

Bonjour,

Un essai...

Ajout de "Sub Client_AfterUpdate" et d'une condition pour ajouter les items dans la listbox.

Private Sub Client_AfterUpdate()  ' <<< ajout
   Me.List.Clear
   Ref_AfterUpdate
End Sub

Private Sub Ref_AfterUpdate()

   If Me.Ref <> "" Then
      'Declaration des variable
      Dim Critere
      Dim DL As Integer
      Dim x As Integer

      'Affectation des variables
      Critere = Me.Ref.Value
      'Recuperation de la dernière ligne
      DL = Cells(Rows.Count, 2).End(xlUp).Row
      'Parcours de la source de données
      For x = 1 To DL
         'Teste critere
         If Cells(x, 4) = Critere Then
            If Cells(x, 3) <> Client Then  '<<< ICI
               'Importation
               Me.List.AddItem Cells(x, 1)
               Me.List.List(Me.List.ListCount - 1, 0) = Cells(x, 1)
               Me.List.List(Me.List.ListCount - 1, 1) = Cells(x, 2)
               Me.List.List(Me.List.ListCount - 1, 2) = Cells(x, 3)
               Me.List.List(Me.List.ListCount - 1, 3) = Cells(x, 4)
               Me.List.List(Me.List.ListCount - 1, 4) = Cells(x, 5)
               Me.List.List(Me.List.ListCount - 1, 5) = Cells(x, 6)
            End If
         End If
      Next x
   End If
End Sub

ric

Bonjour,

Rien dans la ListBox à l'ouverture... Il faudrait expliquer comment tu souhaites te servir de ton userform.

Bonjour

mon code n'est sûrement pas des plus propres, mais vois si cela répond à ta demande.

Cordia5

Cordia5

Bonjour

a toi de voir

A+

Maurice

48bandit-filtre.zip (15.82 Ko)

Bonsoir,

Option Compare Text
Dim f, Rng, TblBD(), NbCol
Private Sub UserForm_Initialize()
  Set f = Sheets("BD")
  Set Rng = f.Range("A2:G" & f.[A65000].End(xlUp).Row)
  NbCol = Rng.Columns.Count - 1
  TblBD = Rng.Value
  For i = 1 To UBound(TblBD): TblBD(i, NbCol + 1) = i: Next i
  Me.ListBox1.List = TblBD
  Me.ListBox1.ColumnCount = NbCol
End Sub

Private Sub TextBox1_Change()
  Affiche
End Sub

Private Sub TextBox2_Change()
  Affiche
End Sub

Private Sub TextBox3_Change()
  Affiche
End Sub

Sub Affiche()
     Dim b()
     tmp1 = Me.TextBox1 & "*":  tmp2 = Me.TextBox2 & "*": tmp3 = Me.TextBox3 & "*"
     n = 0
     For i = LBound(TblBD) To UBound(TblBD)
       If TblBD(i, 3) Like tmp1 And TblBD(i, 4) Like tmp2 And TblBD(i, 1) Like tmp3 Then
         n = n + 1: ReDim Preserve b(1 To NbCol + 1, 1 To n)
         For k = 1 To NbCol + 1: b(k, n) = TblBD(i, k): Next k
       End If
      Next i
      If n > 0 Then Me.ListBox1.Column = b Else Me.ListBox1.Clear
End Sub

Boisgontier

Salut ric, MFerrand, CORDIA5, archer, Boisgontierjacques et le Forum.

Encore une fois c'est un de mes problèmes résolu par des personnes que je ne connais pas mais m'accordent du temps et de la patience.

Merci infiniment à vous 5 pour l'attention et votre temps donné si précieux de nos jours !

CORDIA5 : C'est exactement ce que j'attendais, Merci pour ta proposition qui me sera à présent bien utile.

Les autres comme d'hab, vous ne lâchez rien et c'est réconfortent de ne pas se sentir seul devant une machine aussi cartésienne qu'un ordinateur!!! Vous ramenez le côté humain à la besogne. MERCI !

AFFAIRE RÉSOLUE !!!

Bandit

Bonjour Bandit

Merci pour ton retour.

Cordia5

Rechercher des sujets similaires à "filtre listbox"