Selectionner une ligne de la feuille par la listbox

Bonjour

J'ai trois listbox, j'aimerai que lorsque je click dans une Item de ma listbox sa sélectionne la ligne de ma feuille et sa me rend à la ligne sélectionner

Je vous remercie

Max

Bonjour,

Un essai à adapter à la situation ...

Private Sub ComboBox1_Change()
    Sheets("Feuil1").Activate    ' < sélectionne la feuille concernées
   '  +9 parce que la liste commence à la ligne 9 dans la feuille << à adapter la situation
    Cells(Me.ComboBox1.ListIndex + 9, "C").Select    ' < sélectionne la cellule
    ' ou > une autre façon d'écrire 
    Range("C" & Me.ComboBox1.ListIndex + 9).Select  ' sélectionne la cellule 
    End Sub 

ric

Salut ric

Et merci, sa fonctionne très bien pour la listbox1 qui fait référence à OptionButton1, mon problème est que les deux autre listBox 2 & 3 font référence à OptionButton 2 & 3;

Comment je doit faire

Merci

Max

Re,

Tous fonctionne j'ai mis le code dans chaque Listbox

Je te remercie

A+

max

Bonjour,

Un essai ... à adapter à la situation ...

Option Explicit
Dim Ctrl As Control
Dim Col As String
Dim Choix As Byte

Private Sub UserForm_Initialize()
    OptionButton1 = True
End Sub

Private Sub OptionButton1_Click()
    If OptionButton1 = True Then
        ComboBox1.Clear
        ComboBox1.List = Feuil1.Range("D9:D" & Feuil1.Range("D" & Rows.Count).End(xlUp).Row).Value
        Choix = 15
        Col = "D"
    End If
End Sub

Private Sub OptionButton2_Click()
    If OptionButton2 = True Then
        ComboBox1.Clear
        ComboBox1.List = Feuil1.Range("S9:S" & Feuil1.Range("S" & Rows.Count).End(xlUp).Row).Value
        Choix = 19
        Col = "S"
    End If
End Sub

Private Sub OptionButton3_Click()
    If OptionButton3 = True Then
        ComboBox1.Clear
        ComboBox1.List = Feuil1.Range("AR9:AR" & Feuil1.Range("AR" & Rows.Count).End(xlUp).Row).Value
        Choix = 22
        Col = "AR"
    End If
End Sub

Private Sub ComboBox1_Change()
Dim elem As Byte

 For elem = 1 To Choix   ' << modif
   With Me
   .Controls("TBx_" & elem).Value = .ComboBox1.Column(elem - 1) ' ICI, moins 1
   End With
 Next
    Sheets("Feuil1").Activate
    Cells(Me.ComboBox1.ListIndex + 9, Col).Select
    ' ou
'    Range(Col & Me.ComboBox1.ListIndex + 9).Select
End Sub

ric

Re,

J'ai suivi ton code tous fonctionne très bien sauf la troisième ListBox je comprend pas ?

Dim Ctrl As Control
Dim Col As String
Dim Choix As Byte

Private Sub ListBox1_Change()
  If EnCours = True Then Exit Sub
  With Sheets("feuil1")
    TBx_1.Value = .Cells(ListBox1.ListIndex + 9, 1)
    ComboBox1.Value = .Cells(ListBox1.ListIndex + 9, 2)
    TBx_2.Value = .Cells(ListBox1.ListIndex + 9, 3)
    TBx_3.Value = .Cells(ListBox1.ListIndex + 9, 4)
    TBx_4.Value = .Cells(ListBox1.ListIndex + 9, 5)
    TBx_5.Value = .Cells(ListBox1.ListIndex + 9, 6)
    TBx_6.Value = .Cells(ListBox1.ListIndex + 9, 7)
    TBx_7.Value = .Cells(ListBox1.ListIndex + 9, 8)
    TBx_8.Value = .Cells(ListBox1.ListIndex + 9, 9)
    TBx_9.Value = .Cells(ListBox1.ListIndex + 9, 10)
    TBx_10.Value = .Cells(ListBox1.ListIndex + 9, 11)
    TBx_11.Value = .Cells(ListBox1.ListIndex + 9, 12)
    TBx_12.Value = .Cells(ListBox1.ListIndex + 9, 13)
    TBx_13.Value = .Cells(ListBox1.ListIndex + 9, 14)
    TBx_14.Value = .Cells(ListBox1.ListIndex + 9, 15)
    TBx_15.Value = .Cells(ListBox1.ListIndex + 9, 16)
  End With

End Sub
Private Sub ListBox2_Change()
  If EnCours = True Then Exit Sub
  With Sheets("feuil1")
    TBx_1.Value = .Cells(ListBox2.ListIndex + 9, 17)
    ComboBox1.Value = .Cells(ListBox2.ListIndex + 9, 17)
    TBx_2.Value = .Cells(ListBox2.ListIndex + 9, 18)
    TBx_3.Value = .Cells(ListBox2.ListIndex + 9, 19)
    TBx_4.Value = .Cells(ListBox2.ListIndex + 9, 20)
    TBx_5.Value = .Cells(ListBox2.ListIndex + 9, 21)
    TBx_6.Value = .Cells(ListBox2.ListIndex + 9, 22)
    TBx_7.Value = .Cells(ListBox2.ListIndex + 9, 23)
    TBx_8.Value = .Cells(ListBox2.ListIndex + 9, 24)
    TBx_9.Value = .Cells(ListBox2.ListIndex + 9, 25)
    TBx_10.Value = .Cells(ListBox2.ListIndex + 9, 26)
    TBx_11.Value = .Cells(ListBox2.ListIndex + 9, 27)
    TBx_12.Value = .Cells(ListBox2.ListIndex + 9, 28)
    TBx_13.Value = .Cells(ListBox2.ListIndex + 9, 29)
    TBx_14.Value = .Cells(ListBox2.ListIndex + 9, 30)
    TBx_15.Value = .Cells(ListBox2.ListIndex + 9, 31)
    TBx_16.Value = .Cells(ListBox2.ListIndex + 9, 32)
    TBx_17.Value = .Cells(ListBox2.ListIndex + 9, 33)
    TBx_18.Value = .Cells(ListBox2.ListIndex + 9, 34)
    TBx_19.Value = .Cells(ListBox2.ListIndex + 9, 35)

  End With

End Sub

Private Sub ListBox3_Change()
  If EnCours = True Then Exit Sub
  With Sheets("feuil1")
    TBx_1.Value = .Cells(ListBox3.ListIndex + 9, 17)
    ComboBox1.Value = .Cells(ListBox3.ListIndex + 9, 17)
    TBx_2.Value = .Cells(ListBox3.ListIndex + 9, 18)
    TBx_3.Value = .Cells(ListBox3.ListIndex + 9, 19)
    TBx_4.Value = .Cells(ListBox3.ListIndex + 9, 20)
    TBx_5.Value = .Cells(ListBox3.ListIndex + 9, 21)
    TBx_6.Value = .Cells(ListBox3.ListIndex + 9, 22)
    TBx_7.Value = .Cells(ListBox3.ListIndex + 9, 23)
    TBx_8.Value = .Cells(ListBox3.ListIndex + 9, 24)
    TBx_9.Value = .Cells(ListBox3.ListIndex + 9, 25)
    TBx_10.Value = .Cells(ListBox3.ListIndex + 9, 26)
    TBx_11.Value = .Cells(ListBox3.ListIndex + 9, 27)
    TBx_12.Value = .Cells(ListBox3.ListIndex + 9, 28)
    TBx_13.Value = .Cells(ListBox3.ListIndex + 9, 29)
    TBx_14.Value = .Cells(ListBox3.ListIndex + 9, 30)
    TBx_15.Value = .Cells(ListBox3.ListIndex + 9, 31)
    TBx_16.Value = .Cells(ListBox3.ListIndex + 9, 32)
    TBx_17.Value = .Cells(ListBox3.ListIndex + 9, 33)
    TBx_18.Value = .Cells(ListBox3.ListIndex + 9, 34)
    TBx_19.Value = .Cells(ListBox3.ListIndex + 9, 35)
    TBx_20.Value = .Cells(ListBox3.ListIndex + 9, 36)
    TBx_21.Value = .Cells(ListBox3.ListIndex + 9, 37)
    TBx_22.Value = .Cells(ListBox3.ListIndex + 9, 38)

  End With

End Sub

Private Sub UserForm_Initialize()

For i = 1 To 4
    Me.Controls("Label" & i).Visible = False
Next i
For i = 1 To 20
    Me.Controls("TBx_" & i).Visible = False
Next i

'Alimentation Listbox1
  With ListBox1
    .ColumnCount = 1
    .RowSource = Range("B9:B" & Range("B65536").End(xlUp).Row).Address
  End With
'Alimentation Listbox2
  With ListBox2
    .ColumnCount = 1
    .RowSource = Range("Q9:Q" & Range("Q65536").End(xlUp).Row).Address
  End With

 'Alimentation Listbox2
  With ListBox3
    .ColumnCount = 1
    .RowSource = Range("AJ9:BE" & Range("AJ65536").End(xlUp).Row).Address
  End With

Me.Width = 372
Me.Height = 99
End Sub

Private Sub ComboBox1_Click()
 Dim elem As Byte
 For elem = 1 To Choix   ' << modif
   With Me
   .Controls("TBx_" & elem).Value = .ComboBox1.Column(elem - 1) ' ICI, moins 1
   End With
 Next
     Sheets("Feuil1").Activate
    Cells(Me.ComboBox1.ListIndex + 9, Col).Select
        ' ou
'    Range(Col & Me.ComboBox1.ListIndex + 9).Select

End Sub

Private Sub OptionButton1_Click()
If OptionButton1 = True Then
ComboBox1.Clear
    ComboBox1.List = Feuil1.Range("B9:P" & Feuil1.Range("B" & Rows.Count).End(xlUp).Row).Value
      Choix = 15
        Col = "B"
End If
ListBox1.Visible = True
ListBox2.Visible = False
ListBox3.Visible = False
For i = 1 To 59
    Select Case i
        Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 57 'Label True
            Me.Controls("Label" & i).Visible = True
        Case 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 58, 59 'Label False
            Me.Controls("Label" & i).Visible = False

    End Select
Next i
For i = 1 To 22
    Select Case i
        Case 1 To 15
            Me.Controls("Tbx_" & i).Visible = True 'TextBox Visible
            Me.Controls("Tbx_" & i).Value = ""
        Case 16 To 22
            Me.Controls("Tbx_" & i).Visible = False 'TextBox non Visible
            If i <> 14 Then Me.Controls("Tbx_" & i).Value = ""
    End Select
Next i
ComboBox1.Value = ""

Me.Width = 550
Me.Height = 423
End Sub

Private Sub OptionButton2_Click()
If OptionButton2 = True Then
ComboBox1.Clear
    ComboBox1.List = Feuil1.Range("Q9:AI" & Feuil1.Range("Q" & Rows.Count).End(xlUp).Row).Value
        Choix = 19
        Col = "Q"
End If
ListBox1.Visible = False
ListBox2.Visible = True
ListBox3.Visible = False
For i = 1 To 59
    Select Case i
        Case 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 58 'Label True
            Me.Controls("Label" & i).Visible = True
        Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 59 'Label False
            Me.Controls("Label" & i).Visible = False

    End Select
Next i
For i = 1 To 22
    Select Case i
        Case 1 To 19
            Me.Controls("Tbx_" & i).Visible = True 'TextBox Visible
            Me.Controls("Tbx_" & i).Value = ""
        Case 20 To 22
            Me.Controls("Tbx_" & i).Visible = False 'TextBox non Visible
            If i <> 14 Then Me.Controls("Tbx_" & i).Value = ""
    End Select
Next i
ComboBox1.Value = ""

Me.Width = 550
Me.Height = 498
End Sub

Private Sub OptionButton3_Click()
If OptionButton3 = True Then
ComboBox1.Clear
    ComboBox1.List = Feuil1.Range("AJ9:BE" & Feuil1.Range("AJ" & Rows.Count).End(xlUp).Row).Value
         Choix = 22
        Col = "AJ"
End If
ListBox1.Visible = False
ListBox2.Visible = False
ListBox3.Visible = True
For i = 1 To 59
    Select Case i
        Case 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 59 'Label True
            Me.Controls("Label" & i).Visible = True
        Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 57, 58 'Label False
            Me.Controls("Label" & i).Visible = False

    End Select
Next i
For i = 1 To 22
    Select Case i
        Case 1 To 22
            Me.Controls("Tbx_" & i).Visible = True 'TextBox Visible
            Me.Controls("Tbx_" & i).Value = ""

    End Select
Next i
ComboBox1.Value = ""

Me.Width = 550
Me.Height = 568
End Sub
Private Sub CommandButton1_Click()

Unload Me
End Sub

Mon code au complet:

A+

Max

Bonjour,

Est-ce que tu aurais l'amabilité de mieux décrire ce qui ne fonctionne pas bien avec la 3e listbox ?

Encore mieux, un fichier représentatif faciliterait la recherche de la source du souci.

ric

Re,

Voila une partie de mon fichier que j'ai du raccourcir au maximun

A+

Merci

18essaie-ric.xlsm (32.76 Ko)

Bonjour,

J'ai effectué plusieurs tests sur le fichier soumis ...

Je n'ai décelé aucune erreur ... tout roule correctement.

ric

Re,

Effectivement il n'y a aucune erreur je viens de mettre les 35000 lignes sur le fichier que j'ai mis et sa fonctionne donc je ne comprend pas pourquoi mais bon?????

Je te remercie ric et te souhaite une bonne soirée

Max

Rechercher des sujets similaires à "selectionner ligne feuille listbox"