Bouton recherche -User form

Résolu
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

  1. 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. Merci @f894009 est ce que ça marche aussi pour les drop down list ?
    2. @r4944Re,

      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
    3. Merci , ça marche super bien :))))