Erreur dans code VBA

mavean

XLDnaute Junior
Bonjour
J'ai une feuille de calcul appelé "liste"
Dans cette feuille 500 lignes et 17 colonnes (jusque Q).

J'ai réalisé dans un userform un menu qui me permet à partir d'un code (en colonne f ou d'une désignation en colonne G) d'afficher dans une listebox tous ce qu'il trouve à partir d'une partie de code ou d'une partie de liste.
La demande se fait dans la texbox1 (una partie de code ou de désignation)
l'affichage dans la listbox1
La listbox à 5 colonnes qui récupère les colonnes F G J P Q
J'ai fait ce code VBA en plusieurs fois et il beug au départ ?
Qui peut me le corriger
Merci d'avance.

Private Sub TextBox1_Change()
i = 0
Set plage = Sheets("liste").Range("f10:f" & Sheets("liste").Range("f65536").End(xlUp).Row)
Set plage_a = Sheets("liste").Range("f10:g" & Sheets("liste").Range("g65536").End(xlUp).Row)


NbCol = plage.Columns.Count

Me.ListBox1.Clear
Set c = plage_a.Find(Me.TextBox1, , , xlPart)

If Not c Is Nothing Then
premier = c.Address
Do
Me.ListBox1.AddItem
lig = c.Row - plage.Row + 1
For col = 1 To NbCol
Me.ListBox1.List(i, col - 1) = plage.Cells(lig, col)
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = plage.Cells(lig, col + 1)
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = plage.Cells(lig, col + 4)
Me.ListBox1.List(ListBox1.ListCount - 1, 3) = plage.Cells(lig, col + 10)
Me.ListBox1.List(ListBox1.ListCount - 1, 4) = plage.Cells(lig, col + 11)
Next col
i = i + 1
Set c = plage_a.FindNext(c)
Loop While Not c Is Nothing And c.Address <> premier
End If
If Me.TextBox1 = "" Then Call Initlistbox1
End Sub


Sub Initlistbox1()
With ListBox1
.Clear
.ColumnCount = 5
.ColumnWidths = "80;300;100;80;80"
End With

With Sheets("liste")
If .Range("F10") <> "" Then
Lg = .Range("F65536").End(xlUp).Row
End If

For Mtg = 6 To Lg
If .Cells(Mtg, 8).Value <> "" Then
ListBox1.AddItem .Cells(Mtg, 3)
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(Mtg, 4)
ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(Mtg, 5)
ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(Mtg, 8)
End If
Next Mtg

ListBox1.ListIndex = -1
If ListBox1.ListCount > 0 Then ListBox1.ListIndex = 0
End With
End Sub
 

Discussions similaires

Réponses
4
Affichages
213
Réponses
17
Affichages
840

Statistiques des forums

Discussions
312 216
Messages
2 086 351
Membres
103 195
dernier inscrit
martel.jg