Consulting

Results 1 to 13 of 13

Thread: UserFrom TextBox search in ListBox in the same UserForm?

  1. #1
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location

    UserFrom TextBox search in ListBox in the same UserForm?

    Hello friends.
    I am again with a question for you gods of macros.
    Here it is:
    I have in the excel file:
    userform in it I have:
    ListBox1 and also TextBox1 (and other things), but I am interested how it began to look certain things (in this case name) starts to show me (filtered) only sought or possible. ie something like Andy or Andy Garcia or Gusto Andy Perfetsto, show me all the options (I think it's sort of IF contains).
    Attach some pictures and excel file to target, of course, if this could happen.
    Attached Files Attached Files

  2. #2
    VBAX Regular
    Joined
    Jun 2013
    Posts
    40
    Location
    I am not sure of exactly what you want or need but if I were to guess, your initial goal is to enter a name in the search window and have only that name or similar names appear in the list box. From that list you select the name(s) that meet your criterion. Is this what you want to accomplish?

  3. #3
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hello
    when you look at the file will surely see that I have other buttons at the bottom, which are triggered by other macros.
    I mean when I type the name I want (maybe not first) - >>> just show it to me (filtered) name(s) and then I'll put myself beak (tick) that precede the name in (UserForm).
    Here on this site I found what I want, but it will have to be changed to 100%.
    I am not sure of exactly what you want or need but if I were to guess, your initial goal is to enter a name in the search window and have only that name or similar names appear in the list box. From that list you select the name(s) that meet your criterion. Is this what you want to accomplish? ->>> YES

  4. #4
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Okay, friends, this macro works, but can you help me and tell me where to put the asterisk (*) to be able to search any word, not just the first word.
    Now do the following:
    Ivan Petrovski Kadvistinski
    If I write Ivan - I found the name, but if you write Petrovski - not him alone.
    After a night of surfing the web mention of this (*) to search for any word.
    Thank you in advance, and you may think of another solution.


    Private Sub TextBox1_Change()Dim i As Long
        Dim sFind As String
        
        sFind = Me.TextBox1.Text
        
        If Len(sFind) = 0 Then
            Me.ListBox1.ListIndex = -1
            Me.ListBox1.TopIndex = 0
        Else
            For i = 0 To Me.ListBox1.ListCount - 1
                If UCase(Left(Me.ListBox1.List(i), Len(sFind))) = UCase(sFind) Then
                    Me.ListBox1.TopIndex = i
                    Me.ListBox1.ListIndex = i
                    Exit For
                End If
            Next i
        End If
    End Sub

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Try replacing:
    If UCase(Left(Me.Listbox1.List(i), Len(sFind))) = UCase(sFind) Then
    with:
    If InStr(UCase(Listbox1.List(i)), UCase(sFind)) > 0 Then
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Again and again you helped me.
    Be alive and well.
    A thousand thanks.

  7. #7
    Private Sub TextBox1_Change()Dim i As Long
        Dim sFind As String
        
        sFind = Me.TextBox1.Text
        
        If Len(sFind) = 0 Then
            Me.ListBox1.ListIndex = -1
            Me.ListBox1.TopIndex = 0
        Else
            For i = 0 To Me.ListBox1.ListCount - 1
                If UCase(Left(Me.ListBox1.List(i), Len(sFind))) = UCase(sFind) Then
                    Me.ListBox1.TopIndex = i
                    Me.ListBox1.ListIndex = i
                    Exit For
                End If
            Next i
        End If
    End Sub

    I found this code helpful but i need a modification to this code if you could help me please. How can i get this code to display info of a whole row on a listbox instead of just a single column?


    For example I want the list box display info of those columns

    A - B - C - D
    Name Marry 19 student.

  8. #8
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    For 3 columns, change the named range to :
    =OFFSET(Sheet1!$Z$1,0,0,COUNTA(Sheet1!$Z$2:$Z$104),3)
    and change the ListBox's .ColumnCount property to 3
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  9. #9
    The code is on a userform.

    do i add that on the listbox rowsource?

  10. #10
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Quote Originally Posted by afgg View Post
    The code is on a userform.

    do i add that on the listbox rowsource?
    No, it should already be that, just as I said:
    For 3 columns, change the named range to :
    =OFFSET(Sheet1!$Z$1,0,0,COUNTA(Sheet1!$Z$2:$Z$104),3):
    2017-04-26_191636.jpg
    and:
    "change the ListBox's .ColumnCount property to 3":
    2017-04-26_191723.jpg
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  11. #11
    VBAX Newbie
    Joined
    Oct 2017
    Posts
    1
    Location
    ˇˇThank You so much!!. It helped me a lot

  12. #12

    Post

    Quote Originally Posted by k0st4din View Post
    Hello friends.
    I am again with a question for you gods of macros.
    Here it is:
    I have in the excel file:
    userform in it I have:
    ListBox1 and also TextBox1 (and other things), but I am interested how it began to look certain things (in this case name) starts to show me (filtered) only sought or possible. ie something like Andy or Andy Garcia or Gusto Andy Perfetsto, show me all the options (I think it's sort of IF contains).
    Attach some pictures and excel file to target, of course, if this could happen.
    Need to post to access attachment

  13. #13
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Kost4din's problem was solved 4 years ago.

    This thread is now Closed for replies.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •