• Initiateur de la discussion Initiateur de la discussion fr832
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

fr832

XLDnaute Occasionnel
Bonsoir, j'utilise ce code car je souhaite remplir une listbox, mais ça ne fonctionne pas .
Code:
Private Sub Button_visualiser_Click()
 Dim Lig As Long
  ' La ligne = 1 (ligne de titre) + ListIndex + 1 (car listindex commence à 0)
  Lig = 1 + Me.Combo_engins.ListIndex + 2
  With Sheets("Situation")
    Me.ListBox1 = .Range("B" & Lig)
    Me.ListBox2 = .Range("C" & Lig)
    Me.TextBox4.Value = Format(.Range("E1").Value, "dddd dd mmmm yyyy")
   
  End With
End Sub

Quelle code faut il utiliser pour remplir les listbox ?

Par avance merci
 
Re : remplir une listbox

Re bonjour à tous depuis ce midi j'essaye d'adapter en vain l'excellent travail de robert et forum mais je n'y arrive pas.

Pour le moment voici mon code complet:
Code:
Option Compare Text
Dim n As Byte, Dli As Long
Private f As Worksheet 'déclare la variable f (Feuille)


Private Sub button_quitter_Click()
Unload Me
 
End Sub
'chargement de la listbox





Private Sub UserForm_Initialize()
Set f = Sheets("Situation") 'définit l'onglet f
  Dli = f.Cells(Rows.Count, 1).End(xlUp).Row
  For n = 4 To Dli
    Combo_engins = f.Cells(n, 1)
    If Combo_engins.ListIndex = -1 Then Combo_engins.AddItem Cells(n, 1)
  Next
  n = 0
  
  
Me.TextBox4 = Format(Range("E1").Value, "dddd dd mmmm yyyy")
End Sub
Private Sub Combo_engins_Change()
  ListBox1.Clear
End Sub
Private Sub OptionButton1_Click()
  ListBox1.Clear
  If OptionButton1 Then n = 0
End Sub
Private Sub OptionButton2_Click()
  ListBox1.Clear
  If OptionButton2 Then n = 1
End Sub
Private Sub OptionButton3_Click()
  ListBox1.Clear
  If OptionButton3 Then n = 2
End Sub
Private Sub OptionButton4_Click()
  ListBox1.Clear
  If OptionButton4 Then n = 3
End Sub
Private Sub Button_visualiser_Click()

  With ListBox1
    .Clear
    For l = 4 To Dli
      If f.Cells(l, 1) = Combo_engins Then
        Select Case n
        Case 0
          .AddItem f.Cells(l, 1)
          For Col = 2 To 8
            .List(.ListCount - 1, Col) = f.Cells(l, Col + 1)
          Next
        Case 1
          If f.Cells(l, 7) = "en cours" Then
            .AddItem Cells(l, 1)
            For Col = 2 To 7
              .List(.ListCount - 1, Col) = f.Cells(l, Col + 1)
            Next
          End If
        Case 2
          If f.Cells(l, 7) = "terminé" Then
            .AddItem Cells(l, 1)
            For Col = 2 To 7
              .List(.ListCount - 1, Col) = f.Cells(l, Col + 1)
            Next
          End If
        Case Else
          If f.Cells(l, 7) = "irréparable" Then
            .AddItem f.Cells(l, 1)
            For Col = 2 To 7
              .List(.ListCount - 1, Col) = f.Cells(l, Col + 1)
            Next
          End If
        End Select
      End If
    Next
  End With
   
End Sub

' pour alimenter la combobox en fonction des option button sélectionnés

Private Sub OptionButton_RPC_Click()
  AlimCombo 1
End Sub
Private Sub OptionButton_Caudataire_Click()
  AlimCombo 2
End Sub
Private Sub OptionButton_Levage_Click()
  AlimCombo 3
End Sub
Private Sub OptionButtonPSS10T_Click()
  AlimCombo 4
End Sub

Private Sub OptionButton_PSS4T_Click()
  AlimCombo 5
End Sub
Sub AlimCombo(Cl As Integer)
Dim I As Long

  Me.Combo_engins.Clear
  With Sheets("données")
   For I = 2 To .Cells(65536, Cl).End(xlUp).Row
      Me.Combo_engins = .Cells(I, Cl)
      If Me.Combo_engins.ListIndex = -1 Then
        Me.Combo_engins.AddItem .Cells(I, Cl)
      End If
    Next I
  End With
  Me.Combo_engins.ListIndex = -1
End Sub

L'alimentation de la combobox (combo_engins) subit au préalable un filtre via option button c'est ok tout ça.
La seule chose que je n'arrive pas à modifier c'est mettre la colonne B de la feuille "Situation" dans la listbox en lieu et place de l'engin.

Par avance merci pour vos lumières.
Amitiés
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
10
Affichages
663
Réponses
4
Affichages
755
Réponses
5
Affichages
912
Retour