Renvoi a une ligne a partir d'un double clic listbox

Résolu/Fermé
Raphlight - Modifié par pijaku le 15/12/2015 à 12:29
 Raphlight - 15 déc. 2015 à 14:20
Bonjour,

J'ai un fais une fonction recherche (textbox) et les résultats apparaissent dans différentes "listbox"

Jusque là tout vas bien.

mon code actuel :

Private Sub TextBox1_Change() 'www.blog-excel.com/creer-un-champ-de-recherche-vba
    
    Application.ScreenUpdating = False
 

    ListBox1.Clear 'Exemple 2 (ListBox)
    ListBox2.Clear
    ListBox3.Clear
    ListBox4.Clear
    ListBox5.Clear
    ListBox6.Clear
    ListBox7.Clear
    ListBox8.Clear
    
    If TextBox1 <> "" Then
        For ligne = 11 To 10000
            If Cells(ligne, 1) Like "*" & TextBox1 & "*" Then
                
                ListBox1.AddItem Cells(ligne, 1) 'Exemple 2 (ListBox)
                ListBox2.AddItem Cells(ligne, 2)
                ListBox3.AddItem Cells(ligne, 3)
                ListBox4.AddItem Cells(ligne, 4)
                ListBox5.AddItem Cells(ligne, 5)
                ListBox6.AddItem Cells(ligne, 6)
                ListBox7.AddItem Cells(ligne, 7)
                ListBox8.AddItem Cells(ligne, 8)
            End If
        Next
    End If
 
End Sub 


Ensuite je voudrais pouvoir cliquer sur une ligne de ma listbox et que cela me renvoi a la ligne correspondante dans ma base (juste dessous).
Et je ne vois pas comment faire...

J’espère avoir été assez clair (dans ma tête ce l'est toujours^^)

je vous remercie du dérangement

Cordialement.

A voir également:

4 réponses

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
Modifié par pijaku le 15/12/2015 à 12:34
Bonjour,

Erreur de compréhension...

Désolé.
En fait, il te faut stocker les numéros des lignes dans une seconde colonne cachée d'une listbox.


Avant, j'arrivais jamais à finir mes phrases... mais maintenant je
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
15 déc. 2015 à 12:35
Bonjour,

cliquer sur une ligne de ma listbox Y a 8 TextBoxs, laquelle allez-vous choisir ???????????????????????????????????
0
la une, après je recopierais le code pour appliquer aux autres liste si besoin.
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
15 déc. 2015 à 12:58
Re

Quelque chose comme ceci :

Private Sub TextBox1_Change() 'www.blog-excel.com/creer-un-champ-de-recherche-vba
    
    Application.ScreenUpdating = False
 

    ListBox1.Clear 'Exemple 2 (ListBox)
    ListBox1.ColumnCount = 2
    ListBox1.ColumnWidths = ListBox1.Width & ";0"
    ListBox2.Clear
    ListBox2.ColumnCount = 2
    ListBox2.ColumnWidths = ListBox2.Width & ";0"
    ListBox3.Clear
    ListBox3.ColumnCount = 2
    ListBox3.ColumnWidths = ListBox3.Width & ";0"
    ListBox4.Clear
    ListBox4.ColumnCount = 2
    ListBox4.ColumnWidths = ListBox4.Width & ";0"
    ListBox5.Clear
    ListBox5.ColumnCount = 2
    ListBox5.ColumnWidths = ListBox5.Width & ";0"
    ListBox6.Clear
    ListBox6.ColumnCount = 2
    ListBox6.ColumnWidths = ListBox6.Width & ";0"
    ListBox7.Clear
    ListBox7.ColumnCount = 2
    ListBox7.ColumnWidths = ListBox7.Width & ";0"
    ListBox8.Clear
    ListBox8.ColumnCount = 2
    ListBox8.ColumnWidths = ListBox8.Width & ";0"
    
    If TextBox1 <> "" Then
        For ligne = 11 To 10000
            If Cells(ligne, 1) Like "*" & TextBox1 & "*" Then
                
                ListBox1.AddItem Cells(ligne, 1) 'Exemple 2 (ListBox)
                ListBox1.List(ListBox1.ListCount - 1, 1) = ligne
                ListBox2.AddItem Cells(ligne, 2)
                ListBox2.List(ListBox2.ListCount - 1, 1) = ligne
                ListBox3.AddItem Cells(ligne, 3)
                ListBox3.List(ListBox3.ListCount - 1, 1) = ligne
                ListBox4.AddItem Cells(ligne, 4)
                ListBox4.List(ListBox4.ListCount - 1, 1) = ligne
                ListBox5.AddItem Cells(ligne, 5)
                ListBox5.List(ListBox5.ListCount - 1, 1) = ligne
                ListBox6.AddItem Cells(ligne, 6)
                ListBox6.List(ListBox6.ListCount - 1, 1) = ligne
                ListBox7.AddItem Cells(ligne, 7)
                ListBox7.List(ListBox7.ListCount - 1, 1) = ligne
                ListBox8.AddItem Cells(ligne, 8)
                ListBox8.List(ListBox8.ListCount - 1, 1) = ligne
            End If
        Next
    End If
 
End Sub 
Private Sub ListBox1_Click()
MsgBox ListBox1.List(ListBox1.ListIndex, 1)
End Sub
Private Sub ListBox2_Click()
MsgBox ListBox2.List(ListBox2.ListIndex, 1)
End Sub
Private Sub ListBox3_Click()
MsgBox ListBox3.List(ListBox3.ListIndex, 1)
End Sub
Private Sub ListBox4_Click()
MsgBox ListBox4.List(ListBox4.ListIndex, 1)
End Sub
Private Sub ListBox5_Click()
MsgBox ListBox5.List(ListBox5.ListIndex, 1)
End Sub
Private Sub ListBox6_Click()
MsgBox ListBox6.List(ListBox6.ListIndex, 1)
End Sub
Private Sub ListBox7_Click()
MsgBox ListBox7.List(ListBox7.ListIndex, 1)
End Sub
Private Sub ListBox8_Click()
MsgBox ListBox8.List(ListBox8.ListIndex, 1)
End Sub
 

0
après le clic cela m'annonce le numéro de la ligne correspondante.

Et je voudrais si possible m'y être dirigé directement.

Merci pour votre temps
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744 > Raphlight
Modifié par pijaku le 15/12/2015 à 13:32
Désolé, j'ai cru que vous pourriez adapter seul.
Dans le code donné plus haut, remplacer tous les :
MsgBox ListBox7.List(ListBox7.ListIndex, 1)

Par :
Range("A" & ListBox7.List(ListBox7.ListIndex, 1)).Select


En adaptant, bien sur, le numéro de la listbox...
0
MERCI !

Désolé je touche vraiment le basique et apprend sur le tas.

Pour la suite je vais me débrouiller ;)

Bonne journée tout le monde.
0
Pour la ligne que tu a rajouté :

ListBox1.List(ListBox1.ListCount - 1, 1) = ligne
Cela fait quoi de plus que avant ?

Ainsi que ces deux ligne suplementaire :

ListBox1.ColumnCount = 2
ListBox1.ColumnWidths = ListBox1.Width & ";0"

J’essaye de comprendre plutôt que tout recopier bêtement ^^
0
Avant il me trouvait les résultats avec ou sans majuscule. plus maintenant.
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
15 déc. 2015 à 13:56
Avant il me trouvait les résultats avec ou sans majuscule. plus maintenant.
Les lignes de cde que j'ai ajouté ne changent rien à ta recherche...
Tout se fait là :
If Cells(ligne, 1) Like "*" & TextBox1 & "*" Then

Pour trouver indiféremment avec ou sans majuscules :
If UCase(Cells(ligne, 1)) Like "*" & UCase(TextBox1) & "*" Then


Explications :
ListBox1.ColumnCount = 2 
==> Paramètre la listBox1 en multicolonne avec 2 colonnes
ListBox1.ColumnWidths = ListBox1.Width & ";0" 
==> règle la largeur des deux colonnes :
====> Largeur Colonne 1 = ListBox1.Width (soit la largeur de la listbox)
====> Largeur colonne 2 = 0 (colonne invisible)
ListBox1.List(ListBox1.ListCount - 1, 1) = ligne 
==> place le numéro de la ligne dans la colonne 2 de la listbox (colonne 2 = invisible)



0
Merci pour tout.
0