Bouton recherche -User form

Résolu/Fermé
r4944 Messages postés 122 Date d'inscription vendredi 2 octobre 2015 Statut Membre Dernière intervention 3 mars 2017 - 14 juil. 2016 à 21:05
r4944 Messages postés 122 Date d'inscription vendredi 2 octobre 2015 Statut Membre Dernière intervention 3 mars 2017 - 15 juil. 2016 à 19:02
Bonjour ,

je suis entrain d'essayer d'ajouter un boutton search avec un text box dans un userform (CALENDAR_SLE) , auquel je dois faire une petite recherche avec un ID qui se trouve dans la cellule J$. Je cherche à afficher les données qui se trouvent dans le Tableau excel dans les textbox de la user form, ici j'arrive a faire la recherche mais j'ai pas eu les bonnes resultat c'est toujours le premier Textbox prend le resultat de la dernière cellule du tableau alors que j'ai besoin juste du nom et prénom qui se trouvaient dans les cellules C ET D

voici mon code merci


Private Sub CommandButton6_Click()

Dim FindThis As String

Dim LastColumn, LastRow As Integer

Dim rw, FirstAddress, LastCell, SrchRnge


Calendar_SLE.TextBox1 = ""
Calendar_SLE.TextBox2 = ""

LastRow = Sheet1.Range("$C$2").End(xlDown).Row
LastColumn = Sheet1.Range("$C$2").End(xlToRight).Column
LastCell = Cells(LastRow, LastColumn).Address
SrchRnge = "$C$4:" & LastCell


FindThis = Calendar_SLE.TextBox8



With Sheet1.Range(SrchRnge).Cells

Set rw = .Find(What:=FindThis, After:=Sheet1.Range("$C$4"), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)

End With

On Error GoTo notfound

Calendar_SLE.TextBox1 = Sheet1.Range("C1").Offset(Range(rw.Address).Row - 1, Range(rw.Address).Column)
' Calendar_SLE.TextBox2 = Sheet1.Range("C1").Offset(Range(rw.Address).Row - 1, Range(rw.Address).Column + 1)



notfound:

If Calendar_SLE.TextBox2 = "" Then

MsgBox ("No Result for " & FindThis)

Else
End If


End Sub

1 réponse

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
15 juil. 2016 à 09:40
Bonjour,

code modifie a minima, vous connaissez les colonnes donc pourquoi vous compliquer la vie !!!!

Private Sub CommandButton6_Click()
    Dim FindThis As String
    Dim LastColumn, LastRow As Integer
    Dim rw, FirstAddress, LastCell, SrchRnge
   
    TextBox1 = ""
    TextBox2 = ""
    With Worksheets("feuil1")
        LastRow = .Range("$C$2").End(xlDown).Row
        LastColumn = .Range("$C$2").End(xlToRight).Column
        LastCell = .Cells(LastRow, LastColumn).Address
        SrchRnge = "$C$4:" & LastCell
        FindThis = TextBox8
        With .Range(SrchRnge).Cells
            rw = .Find(What:=FindThis, After:=.Range("$C$4"), LookIn:=xlValues, LookAt:= _
                            xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
        End With
     
        On Error GoTo notfound
     
        TextBox1 = .Range("C" & rw)
        TextBox2 = .Range("D" & rw)
    End With
    
notfound:
    If TextBox2 = "" Then
        MsgBox ("No Result for " & FindThis)
    Else
    End If
     

End Sub
1
r4944 Messages postés 122 Date d'inscription vendredi 2 octobre 2015 Statut Membre Dernière intervention 3 mars 2017
15 juil. 2016 à 15:33
Merci @f894009 est ce que ça marche aussi pour les drop down list ?
0
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701 > r4944 Messages postés 122 Date d'inscription vendredi 2 octobre 2015 Statut Membre Dernière intervention 3 mars 2017
15 juil. 2016 à 15:40
Re,

Oui, si dans le code
FindThis = TextBox8
, vous affectez FindThis a la valeur selectionnee dans votre liste de validation ou combobox et modifiez l'appel du code suivant le type de list
0
r4944 Messages postés 122 Date d'inscription vendredi 2 octobre 2015 Statut Membre Dernière intervention 3 mars 2017
15 juil. 2016 à 19:02
Merci , ça marche super bien :))))
0