Search in textbox1 VBA in a form

titivaler

New Member
Joined
May 1, 2018
Messages
3
I am trying to search a word in a textbox, it shows in a listbox what I am looking for, the texbox1 code works well, the issue is the second code "selec", when I select the correct one, it does not do anything. I would like to select the word in the listbox, press enter and have it populatedin the textbox as when you are looking something from google,

If I erase somehting in the textbox, and write another word, press enter in the listbox, then the texbox should be populated

thank you

Code:
Private Sub TextBox1_Change()

       
        Dim rng As Range, e
        Set Lista = Range("lstProductos")
        With Me
            .ListBox1.Clear


            For Each i In Lista.Value
                If (i <> "") * (i Like "*" & .TextBox1.Value & "*") Then
                    .ListBox1.AddItem i
                End If
            Next i


        End With
    
End Sub


Private Sub selec()


    Cuenta = Me.ListBox1.ListCount


    For i = 0 To Cuenta - 1


        If Me.ListBox1.Selected(i) = True Then
        texbox1.Value = Me.ListBox1.List(i) ' does not work
        End If


    Next i


End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Just a guess...

Code:
If Me.ListBox1.Selected(i) = True Then
        texbox1.Value = Me.ListBox1.List(i) ' does not work
End If

maybe "texbox1" should be "TextBox1"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top