Problème remplissage listbox

remse Messages postés 14 Date d'inscription   Statut Membre Dernière intervention   -  
f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Je code depuis très peu avec visual basic. J'ai fait une sorte de formulaire qui fonctionne bien avec un mode recherche basic.
J'ai voulu rajouter des colonnes supplémentaires a mon fichier et réadapter mon code. Cependant, j'ai une erreur qui persiste par rapport au remplissage de ma ListBox. La fonction List () n'arrive pas récupérer les données du fichiers excel et ce dans une colonne bien précis.

Merci d'avance pour votre aide.

Mon code:

Option Explicit 'oblige à déclarer toutes les variables
Option Compare Text 'utilise le texte pour le classement alphabétique
Private x As Byte 'déclare la variable x
Private pl As Range 'déclare la variable pl (PLage)
Private cel As Range 'déclare la variable cel (CELlule)
Private nl As Long 'déclare la variable nl (Numéro de Lige)



Private Sub UserForm_Initialize()
Call obG1
End Sub
Private Sub OptionButton1_Click()
Call obG1
End Sub
Private Sub OptionButton2_Click()
Call obG1
End Sub
Private Sub OptionButton3_Click()
Call obG2
End Sub
Private Sub OptionButton4_Click()
Call obG2
End Sub

Private Sub OptionButton5_Click()
Call obG2
End Sub



Private Sub ComboBox1_DropButtonClick()
If Me.ComboBox1.ListCount = 0 Then
MsgBox "Vous devez choisir le type de recherche !"
Me.OptionButton3.SetFocus
End If
End Sub

Private Sub ComboBox1_Change()
Me.ListBox1.Clear
For Each cel In pl
If CStr(cel.Value) = CStr(Me.ComboBox1.Value) Then
nl = cel.Row


Me.ListBox1.AddItem Sheets("Suivi").Cells(cel.Row, 1)
With Me.ListBox1
.List(.ListCount - 1, 1) = Sheets("Suivi").Cells(cel.Row, 2)
.List(.ListCount - 1, 2) = Sheets("Suivi").Cells(cel.Row, 3)
.List(.ListCount - 1, 3) = Sheets("Suivi").Cells(cel.Row, 4)
.List(.ListCount - 1, 4) = Sheets("Suivi").Cells(cel.Row, 5)
.List(.ListCount - 1, 5) = Sheets("Suivi").Cells(cel.Row, 6)
.List(.ListCount - 1, 6) = Sheets("Suivi").Cells(cel.Row, 7)
.List(.ListCount - 1, 7) = Sheets("Suivi").Cells(cel.Row, 8)
.List(.ListCount - 1, 8) = Sheets("Suivi").Cells(cel.Row, 9)
.List(.ListCount - 1, 9) = Sheets("Suivi").Cells(cel.Row, 10)
.List(.ListCount - 1, 10) = Sheets("Suivi").Cells(cel.Row, 11)
.List(.ListCount - 1, 11) = Sheets("Suivi").Cells(cel.Row, 12)
.List(.ListCount - 1, 12) = nl
End With
End If
Next cel
If Me.ListBox1.ListCount = 1 Then Me.ListBox1.ListIndex = 0
End Sub

Private Sub ListBox1_Click()


For x = 0 To 3 'modifier

Me.Controls("TextBox" & x + 1).Value = Me.ListBox1.Column(x, Me.ListBox1.ListIndex)
Next x

'modifier

' Me.Controls("TextBox5").Value = Me.ListBox1.Column(11, Me.ListBox1.ListIndex)

nl = Me.ListBox1.Column(12, Me.ListBox1.ListIndex)
With Me.TextBox3 'modifier
.SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End With
End Sub

Private Sub CommandButton1_Click()

Dim dest As Range
With Sheets("Suivi")
If nl = 0 Then

Set dest = .Cells(Application.Rows.Count, 1).End(xlUp).Offset(1, 0)
Else
Set dest = .Cells(nl, 1) ' modifier A REVOIR
End If
End With
For x = 0 To 3 'modifierfd

dest.Offset(0, x).Value = Me.Controls("TextBox" & x + 1).Value
Next x

For x = 4 To 5 'modifierdate '5 et 6 colonne

dest.Offset(0, x).Value = Me.Controls("ComboBox" & x - 2).Value
Next x

For x = 6 To 8

dest.Offset(0, x).Value = Me.Controls("DTPicker" & x - 5).Value
Next x

For x = 9 To 9 'Perte Vol

dest.Offset(0, x).Value = Me.Controls("ComboBox4").Value
Next x

For x = 10 To 10 'Commentaire

dest.Offset(0, x).Value = Me.Controls("TextBox5").Value
Next x
Unload Me
UserForm1.Show
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub obG1()
UserForm1.Frame1.Visible = UserForm1.OptionButton2.Value
If Me.OptionButton1.Value = True Then
For x = 1 To 4 'modifier
Me.Controls("TextBox" & x).Value = ""
Next x

Me.TextBox1.SetFocus
nl = 0
End If
End Sub

Private Sub obG2()
Dim col As Byte
Dim dico As Object
Dim tbl As Variant
Dim i As Integer
Dim j As Integer
Dim temp As Variant

UserForm1.ComboBox1.Clear

'col = IIf(UserForm1.OptionButton3.Value = True, UserForm1.OptionButton4.Value = True, UserForm1.OptionButton5.Value = True, 1, 4, 6) 'modifier 5 2

If (UserForm1.OptionButton3.Value = True) Then
col = 1
Else

If (UserForm1.OptionButton4.Value = True) Then

col = 4

Else
If (UserForm1.OptionButton5.Value = True) Then

col = 6

End If
End If
End If


With Sheets("Suivi")
'recherche
Set pl = .Range(.Cells(7, col), .Cells(Application.Rows.Count, col).End(xlUp)) 'définit la plage pl
End With

Set dico = CreateObject("scripting.dictionary")
For Each cel In pl
dico(cel.Value) = ""
Next cel
tbl = dico.keys


For i = 0 To UBound(tbl, 1)
For j = 0 To UBound(tbl, 1)
If tbl(i) < tbl(j) Then
temp = tbl(i)
tbl(i) = tbl(j)
tbl(j) = temp
End If
Next j
Next i
UserForm1.ComboBox1.List = tbl


End Sub


3 réponses

f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention   1 713
 
Bonjour remse, bonjour Heliotte,

Nombre maxi colonnes listbox excel: 10 ( de 1 a 10)
3
Heliotte Messages postés 1491 Date d'inscription   Statut Membre Dernière intervention   92
 
Bonjour f894009,

C'est déjà pas mal 10 !
0
f894009 Messages postés 17277 Date d'inscription   Statut Membre Dernière intervention   1 713
 
Bonjour,
Si besoin de plus de colonne, il faut passer par une listview du VB6.0.

Bye
0
Heliotte Messages postés 1491 Date d'inscription   Statut Membre Dernière intervention   92
 
Bonsoir remse,

Je pense que vous pourriez obtenir la valeur de la cellule dans cette colonne, mais pas l'ajouter à la ComboBox !
0
remse Messages postés 14 Date d'inscription   Statut Membre Dernière intervention  
 
Bonsoir,

Ah c'est bon à savoir. Je réduirai mes colonnes à afficher dans ce cas là. Merci à vous deux! ^^
0