XL 2016 problème de filtre dans listbox

saidoush

XLDnaute Junior
Bonjour à tous !!!

J'ai fais un petit formulaire de saisie pour suivre les locations de véhicule perso.
en revanche je ne trouve pas le moyens de rajouter une fonction modifier et filtrer.

j'ai beau rajouter ce code...en vain.

Private Sub FilterListBox()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Synthèse")

Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, "I").End(xlUp).Row

Dim filterValue As String
filterValue = UCase(ComboBox4.Value)

' Supprimer tous les éléments actuels de la ListBox1
Dim i As Long
For i = ListBox1.ListCount - 1 To 0 Step -1
ListBox1.RemoveItem i
Next i

Dim rowCounter As Long
rowCounter = 0

For i = 11 To LastRow
If InStr(1, UCase(ws.Cells(i, "I").Value), filterValue) > 0 Then
ListBox1.AddItem ws.Cells(i, "A").Value
ListBox1.List(rowCounter, 1) = ws.Cells(i, "B").Value
ListBox1.List(rowCounter, 2) = ws.Cells(i, "C").Value
ListBox1.List(rowCounter, 3) = ws.Cells(i, "D").Value
ListBox1.List(rowCounter, 4) = ws.Cells(i, "E").Value
ListBox1.List(rowCounter, 5) = ws.Cells(i, "F").Value
ListBox1.List(rowCounter, 6) = ws.Cells(i, "G").Value
ListBox1.List(rowCounter, 7) = ws.Cells(i, "H").Value
ListBox1.List(rowCounter, 8) = ws.Cells(i, "I").Value
ListBox1.List(rowCounter, 9) = ws.Cells(i, "J").Value
ListBox1.List(rowCounter, 10) = ws.Cells(i, "K").Value
ListBox1.List(rowCounter, 11) = ws.Cells(i, "L").Value
rowCounter = rowCounter + 1
End If
Next i
End Sub
 

Pièces jointes

  • SUIVI LOCATIONS 2024.xlsm
    50.7 KB · Affichages: 9

ChTi160

XLDnaute Barbatruc
Bonjour Saidoush
Tu peux déjà remplacer .
VB:
Supprimer tous les éléments actuels de la ListBox1
Dim i As Long
For i = ListBox1.ListCount - 1 To 0 Step -1
ListBox1.RemoveItem i
Next i
Par
Code:
LitBox1.Clear
une boucle en moins lol
L'autre pour charger, peux elle aussi être simplifiée.
je regarde des que possible
Jean marie
Édit : depuis mon téléphone
 

ChTi160

XLDnaute Barbatruc
Bonjour saidoush ,Gérard

Tu utilises aussi d'un coté la propriété RowSource et de l'autre Additem (c'est pas Possible) Job75 a raison il faut passer par un tableau pour charger ton Userform lorsqu'il contient plus de 10 colonnes (je regarde)
Jean marie
 

saidoush

XLDnaute Junior
J'ai essayé ca mais .... même problème

ListBox1.Clear



Private Sub FilterListBox()
Dim searchTerm As String
Dim ws As Worksheet
Dim LastRow As Long
Dim i As Long
Dim j As Long
Dim filteredList As Variant
searchTerm = UCase(ComboBox4.Value)
ListBox1.Clear
If Len(searchTerm) > 0 Then
Set ws = ThisWorkbook.Sheets("Synthèse")
LastRow = ws.Cells(ws.Rows.Count, "I").End(xlUp).Row
filteredList = ws.Range("I11:I" & LastRow).Value
For i = 1 To UBound(filteredList)
If InStr(1, UCase(filteredList(i, 1)), searchTerm) > 0 Then
ListBox1.AddItem ws.Cells(i + 10, "A").Resize(1, 12).Value
End If
Next i
Else
show_data_in_listbox
End If
End Sub
 

ChTi160

XLDnaute Barbatruc
Re
je te mets le fichier ou je n'ai fait que charger la ListBox a l'ouverture du Userform pour que tu regardes !
et tu me dis !
ne tente rien d'autre , je n'ai rien fait ailleurs que là Lol
Jean marie
 

Pièces jointes

  • SUIVI LOCATIONS 2024 Chti160-1.xlsm
    46.2 KB · Affichages: 2

Discussions similaires

Réponses
0
Affichages
153
Réponses
1
Affichages
168
Réponses
2
Affichages
242
Réponses
4
Affichages
213

Statistiques des forums

Discussions
312 241
Messages
2 086 524
Membres
103 242
dernier inscrit
Patoshick