XL 2019 Je veux afficher mes données dans ma Listbox1 avec l'entete de ma Base donnée et fait la recherche sans que cela derange l'entete.

Orlymax

XLDnaute Nouveau
Bonjour!
je voudrais que vous m'aidiez à afficher l'entete de mes données de ma BD qui se trouve sur une feuille nommée "BD_TER" dans une listbox1 de mon Ecran_TER. et faciliter la recherche.
J'ai déjà 4 Textbox de recherche qui recherche des données sur une feuille "BD_TER" en fonction d'un texte saisi dans un Textbox "TB_RECHERCHE" mais je rendre les difilculter. J'ai réussi à afficher toutes les données de la feuille BD_TER dans ma listebox1, mais ce que je souhaite maintenant c'est de les filtrer en fonction de Textbox1 "TB_RECHERCHE" et Textbox2 "TB_RECHERCHE_1" et Textbox3 "TB_RECHERCHE_2" et Textbox4 "TB_RECHERCHE_3" sans la prise en compte de l'entete de ma listbox1. J'ai voulu afficher l'entete de ma "BD_TER" dans ma listbox1 et j'ai reussi a le faire mais le probleme est que lorsque j'effectue la recherche... Je rencontre le problme : Erreur de compilation Variable non definir.
Pour resumer: je veux afficher mes données dans ma Listbox1 avec l'entete de ma Base donnée et fait la recherche sans que cela derange l'entete. Que la recherche prend en compte juste les données qui se trouve dans la Ligne A5. l'entete se trouve dans la ligne A4.
VB:
Option Explicit
Dim rngData As Range
Private Sub UserForm_Initialize()
Set rngData = ThisWorkbook.Worksheets("BD_TER").Range("A5").CurrentRegion
With rngData
ListBox1.RowSource = .Offset(1).Resize(.Rows.Count - 1).Address(external:=True) ' Les données
ListBox1.ColumnHeads = True
ListBox1.ColumnCount = .Columns.Count
End With
 
On Error Resume Next
Call show_data_in_listbox

End Sub

Function show_data_in_listbox()
ListBox1.ColumnCount = 16
ListBox1.ColumnWidths = "0 pt;95 pt;95 pt;95 pt;95 pt;110 pt;210 pt;60 pt;110 pt;110 pt;250 pt;95 pt;120 pt;95 pt;95 pt;130 pt;210 pt"
Sheets("BD_TER").Activate
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.List = Range("A5:P" & lastrow).Value

'ListBox1.RowSource = "BD_TER!A5:P" & lastrow
'ListBox1.ColumnHeads = True
End Function



Private Sub Cmd_ajouter_Click()

On Error Resume Next
SHALOOM_TERRAIN.Show

End Sub

Private Sub ListBox1_Change()
Nombre_T8.Caption = ListBox1.ListCount
End Sub

Private Sub UserForm_Activate()
Nombre_T8.Caption = ListBox1.ListCount
End Sub
Private Sub TB_RECHERCHE_3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If InStr("1234567890", Chr(KeyAscii)) = 0 Then KeyAscii = 0

End Sub


Private Sub TB_RECHERCHE_3_Change()

On Error Resume Next
Call show_data_in_listbox

Dim Lign As Integer
Dim ListCount1 As Integer

ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE_3 <> "" Then

' 2 = colonne 3
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 12), TB_RECHERCHE_3) = False Then
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If
End Sub
Private Sub TB_RECHERCHE_2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If InStr("1234567890", Chr(KeyAscii)) = 0 Then KeyAscii = 0

End Sub

Private Sub TB_RECHERCHE_2_Change()

On Error Resume Next
Call show_data_in_listbox

Dim Lign As Integer
Dim ListCount1 As Integer


ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE_2 <> "" Then

' 2 = colonne 3
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 11), TB_RECHERCHE_2) = False Then
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If
End Sub

Sub TB_RECHERCHE_Change()

On Error Resume Next
Call show_data_in_listbox


Dim Lign As Integer
Dim ListCount5 As Integer

ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE <> "" Then

' 0 = colonne 5 CODE AGNET
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 4), TB_RECHERCHE) = False Then
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If

TB_RECHERCHE = UCase(TB_RECHERCHE)

End Sub

Sub TB_RECHERCHE_1_Change()
Call show_data_in_listbox

Dim lastrow As Integer
Dim ListCount1 As Integer

ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE_1 <> "" Then

' 1 = colonne 4 ID-CLIENT
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 3), TB_RECHERCHE_1) = False Then
'ListBox1.RemoveItem (lastrow)
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If

TB_RECHERCHE_1 = UCase(TB_RECHERCHE_1)

End Sub
 

ChTi160

XLDnaute Barbatruc
Tu fais :
VB:
ListBox1.RowSource = .Offset(1).Resize(.Rows.Count - 1).Address(external:=True)
Puis dans ta fonction "show_data_in_listbox()"
Code:
ListBox1.List = Range("A5:P" & lastrow).Value
Ça vient peut être de la tu pourrais peut être supprimer
VB:
ListBox1.RowSource = .Offset(1).Resize(.Rows.Count - 1).Address(external:=True)
A voir
Déplus tu fais :
Code:
Range("A5:P"
Pourquoi pas A4 au lieu de A5 A4 qui est la ligne d'entête.
Jean marie
Depuis mon téléphone !
 

Orlymax

XLDnaute Nouveau
Tu fais :
VB:
ListBox1.RowSource = .Offset(1).Resize(.Rows.Count - 1).Address(external:=True)
Puis dans ta fonction "show_data_in_listbox()"
Code:
ListBox1.List = Range("A5:P" & lastrow).Value
Ça vient peut être de la tu pourrais peut être supprimer
VB:
ListBox1.RowSource = .Offset(1).Resize(.Rows.Count - 1).Address(external:=True)
A voir
Déplus tu fais :
Code:
Range("A5:P"
Pourquoi pas A4 au lieu de A5 A4 qui est la ligne d'entête.
Jean marie
Depuis mon téléphone !
Lorsque je definis
A4 au lieu de A5 A4 qui est la ligne d'entête
Et je fais une recherche dans mes Textbox ... (TB_RECHERCHE_3, TB_RECHERCHE_2, TB_RECHERCHE_1 ou TB_RECHERCHE) l'en tête de ma base de donnée disparait... et laisse place a la ligne A5 des données. Je souhaiterais faire une recherche et avoir l'en tête fixe.

VB:
Function show_data_in_listbox()
ListBox1.ColumnCount = 16
ListBox1.ColumnWidths = "0 pt;95 pt;95 pt;95 pt;95 pt;110 pt;210 pt;60 pt;110 pt;110 pt;250 pt;95 pt;120 pt;95 pt;95 pt;130 pt;210 pt"
Sheets("BD_TER").Activate
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.List = Range("A4:P" & lastrow).Value

'ListBox1.RowSource = "BD_TER!A5:P" & lastrow
'ListBox1.ColumnHeads = True
End Function



Private Sub Cmd_ajouter_Click()

On Error Resume Next
SHALOOM_TERRAIN.Show

End Sub

Private Sub ListBox1_Change()
Nombre_T8.Caption = ListBox1.ListCount
End Sub

Private Sub UserForm_Activate()
Nombre_T8.Caption = ListBox1.ListCount
End Sub
Private Sub TB_RECHERCHE_3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If InStr("1234567890", Chr(KeyAscii)) = 0 Then KeyAscii = 0

End Sub


Private Sub TB_RECHERCHE_3_Change()

On Error Resume Next
Call show_data_in_listbox

Dim Lign As Integer
Dim ListCount1 As Integer

ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE_3 <> "" Then

' 2 = colonne 3
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 12), TB_RECHERCHE_3) = False Then
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If
End Sub
Private Sub TB_RECHERCHE_2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If InStr("1234567890", Chr(KeyAscii)) = 0 Then KeyAscii = 0

End Sub

Private Sub TB_RECHERCHE_2_Change()

On Error Resume Next
Call show_data_in_listbox

Dim Lign As Integer
Dim ListCount1 As Integer


ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE_2 <> "" Then

' 2 = colonne 3
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 11), TB_RECHERCHE_2) = False Then
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If
End Sub

Sub TB_RECHERCHE_Change()

On Error Resume Next
Call show_data_in_listbox


Dim Lign As Integer
Dim ListCount5 As Integer

ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE <> "" Then

' 0 = colonne 5 CODE AGNET
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 4), TB_RECHERCHE) = False Then
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If

TB_RECHERCHE = UCase(TB_RECHERCHE)

End Sub

Sub TB_RECHERCHE_1_Change()
Call show_data_in_listbox

Dim lastrow As Integer
Dim ListCount1 As Integer

ListCount1 = ListBox1.ListCount - 1 '---------Erreur de compilation Variable non definir
If Me.TB_RECHERCHE_1 <> "" Then

' 1 = colonne 4 ID-CLIENT
For Lign = ListCount1 To 0 Step -1
If InStr(1, ListBox1.List(Lign, 3), TB_RECHERCHE_1) = False Then
'ListBox1.RemoveItem (lastrow)
ListBox1.RemoveItem (Lign)

End If
Next Lign
End If

TB_RECHERCHE_1 = UCase(TB_RECHERCHE_1)

End Sub


Private Sub UserForm_Initialize()

On Error Resume Next
Call show_data_in_listbox

End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 209
Messages
2 086 267
Membres
103 168
dernier inscrit
isidore33