Problème affiche du résultat via une listbox

Bonjour,

Je cherche à afficher résultats des doublons présents dans mon fichier de recherche. Quand je veux faire afficher les résultats complémentaires par rapport à un doublon. C'est que le premier résultat qui s'affiche et pas les autres quand je double clique sur la ligne.

image

Le code correspondant à l'endroit du double clic pour afficher les valeurs :

'*************************
'Procédure permettant d'affciher les doublons et de double-click sur un doublon pour affichage
'*************************
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim no_ligne As Integer
no_ligne = ListeArticle.ListIndex + 2

    txtValac.Text = Cells(no_ligne, 1).Text
    txtRep.Value = Cells(no_ligne, 2).Value
    txtArticle.Value = Cells(no_ligne, 3).Value
    txtDesignat.Value = Cells(no_ligne, 4).Value
    txtFab.Value = Cells(no_ligne, 5).Value
    txtRefFab.Value = Cells(no_ligne, 6).Value
    txtNbStt.Value = Cells(no_ligne, 7).Value
    txtCasEmploi.Value = Cells(no_ligne, 8).Value
    bxStat.Value = Cells(no_ligne, 9).Value
    bxNatDem.Value = Cells(no_ligne, 10).Value
    txtRefDoc.Value = Cells(no_ligne, 11).Value
    txtLBO.Value = Cells(no_ligne, 12).Value
    bxLEVEL.Value = Cells(no_ligne, 13).Value
    txtDem.Value = Cells(no_ligne, 14).Value
    bxRespVS.Value = Cells(no_ligne, 15).Value
    txtTPS.Value = Cells(no_ligne, 16).Value
    bxPrio.Value = Cells(no_ligne, 17).Value
    txtObser.Value = Cells(no_ligne, 18).Value
    bxTypeVal.Value = Cells(no_ligne, 19).Value
    txtDSH.Value = Cells(no_ligne, 20).Value
    txtRetRU.Value = Cells(no_ligne, 21).Value

End Sub

'*************************
'Procédure permettant de rechercher des valeurs dans la base de données
'*************************
Private Sub ListeArticle_Change()

Dim no_ligne As Integer
no_ligne = ListeArticle.ListIndex + 2
Application.ScreenUpdating = False
 ListBox2.Clear

    If ListeArticle <> "" Then
      For Ligne = 2 To 300
            If ActiveSheet.Cells(Ligne, 3) Like "*" & ListeArticle & "*" Then
                ListBox2.AddItem "[A" & Ligne & "] - VALAC " & ActiveSheet.Cells(Ligne, 1).Text & " - " & ActiveSheet.Cells(Ligne, 10) & " " & ActiveSheet.Cells(Ligne, 11) & " \ " & ActiveSheet.Cells(Ligne, 9)
            End If
        Next
       txtValac.Text = Cells(no_ligne, 1).Text
       txtRep.Value = Cells(no_ligne, 2).Value
       txtArticle.Value = Cells(no_ligne, 3).Value
       txtDesignat.Value = Cells(no_ligne, 4).Value
       txtFab.Value = Cells(no_ligne, 5).Value
       txtRefFab.Value = Cells(no_ligne, 6).Value
       txtNbStt.Value = Cells(no_ligne, 7).Value
       txtCasEmploi.Value = Cells(no_ligne, 8).Value
       bxStat.Value = Cells(no_ligne, 9).Value
       bxNatDem.Value = Cells(no_ligne, 10).Value
       txtRefDoc.Value = Cells(no_ligne, 11).Value
       txtLBO.Value = Cells(no_ligne, 12).Value
       bxLEVEL.Value = Cells(no_ligne, 13).Value
       txtDem.Value = Cells(no_ligne, 14).Value
       bxRespVS.Value = Cells(no_ligne, 15).Value
       txtTPS.Value = Cells(no_ligne, 16).Value
       bxPrio.Value = Cells(no_ligne, 17).Value
       txtObser.Value = Cells(no_ligne, 18).Value
       bxTypeVal.Value = Cells(no_ligne, 19).Value
       txtDSH.Value = Cells(no_ligne, 20).Value
       txtRetRU.Value = Cells(no_ligne, 21).Value
    End If
End Sub

Merci d'avance !

Bonjour

Tu devrais joindre ton fichier...

Bye !

Je voudrais bien mais il y a des données confidentielles ...

EDIT :

Après avoir anonymisé toutes les données voici le fichier en question

Pour le bug il faut se rendre sur cet onglet

image

Et ensuite cliquer sur "Anciennes années" et rentrer le code "AY13100706" dans recherche pour recréer le bug :

image

Bonjour à tous,

Si j'ai bien compris la demande ...
L'on double-clic sur une ligne de la listbox2 et les infos s'inscrivent dans les différents contrôls ...

Pour avoir le bon numéro de ligne > il faut l'extraire du [A47] .... > 47 étant le numéro de la ligne dans la feuille ...

Il faut gérer les cas ou [A1] > [A47] > et même [A1254] > codé ainsi > il n'y a pas de limite au nombre de chiffre ...

ric

Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim no_ligne As Integer, Laligne As String, X As Byte

Laligne = Me.ListBox2.List(Me.ListBox2.ListIndex)

X = InStr(Laligne, "]")
Laligne = Left(Laligne, X - 1)
no_ligne = CInt(Right(Laligne, Len(Laligne) - 2))

    txtValac.Text = Cells(no_ligne, 1).Text
    ' ...
    ' ...

Salut Ric,

Je te remercie pour la réponse mais il plante et affiche cette erreur :

image image

Alors quelques explications complémentaires :

Si j'ai bien compris la demande ...

L'on double-clic sur une ligne de la listbox2 et les infos s'inscrivent dans les différents contrôls ...

Oui c'est cela, si je voudrais afficher les info de la ligne A[51] par exemple. Je double-clique et je fais afficher les infos de cette ligne sur les différents champs de l'userform.

Le but est d'éviter de chercher dans la ComboBox "Recherche" l'autre doublon.

Bonne journée !

Bonjour,

Dans le code que je t'ai soumis > les 3 variables sont sur la même ligne et séparées par des virgules ...

Si tu veux les séparer en les plaçant sur des lignes différentes > il faut inscrire "Dim " devant ...

Ceci :

Dim no_ligne As Integer, Laligne As String, X As Byte

Est l'équivalent de :

Dim no_ligne As Integer
Dim Laligne As String
Dim X As Byte

Je t'invite à suivre les cours VBA > afin d'améliorer tes bases > https://www.excel-pratique.com/fr/vba

ric

En effet, la fatigue est présente...

Merci encore !

Rechercher des sujets similaires à "probleme affiche resultat via listbox"