+ Reply to Thread
Results 1 to 10 of 10

Use TextBox as search in ListBox (string or number)

  1. #1
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Use TextBox as search in ListBox (string or number)

    Hello,
    I got this ListBox with Names and numbers, I would like to be able to use TextBox above as search through it, any part of text or number. I've found some online code but I haven't been able to modify it to my needs. Any help appreciated.
    vaZ5gIU.jpg
    Last edited by Pojzon; 11-10-2021 at 10:33 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Use TextBox as search in ListBox (string or number)

    Do you want to just find the first match, or do you want to find all matches?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Use TextBox as search in ListBox (string or number)

    Oh sorry, I would like to find all matches.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Use TextBox as search in ListBox (string or number)

    Your screenshot looks like it might be a userform. In the future please attach your file, because this context is important. Here is a solution for a userform:

    Please Login or Register  to view this content.
    Your listbox MultiSelect property must be set to fmMultiSelectMulti.

  5. #5
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Use TextBox as search in ListBox (string or number)

    It is userform indeed, I've made another screenshot, hopefully better this time:
    Attachment 754544
    What I'm trying to get is: user writes some letters or numbers in textbox(search) and listbox get's populated only with rows that contain these characters. Then user selects one row value from list of found rows so I actually want ListBox to be MultiSelectSingle type. After selecting row user presses OK and I'll be getting ListBox.Text from that. I believe me.ListBox.clear would be also needed in code in order to empty it of the rows that don't fit? Also perhaps TextBox should be "AfterUpdate" event instead of "Change"? I don't know, anyway I hope that I made it clearer this time.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Use TextBox as search in ListBox (string or number)

    This is different than what your first post says, which is that you want to search through the listbox. If you want to populate the list box based on a search of data in a worksheet you are going to have to provide all of the details about where the data is. The best thing is to attach your file with sample data (see yellow banner at the top of the page). You also need to describe how you want the search to work from the user's point of view. Do you want the listbox to be refreshed every time there is any change to the textbox? Or do you want to add a Search button so the user can populate the listbox when he has completed the textbox?

  7. #7
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Use TextBox as search in ListBox (string or number)

    I'm afraid I can't share this excel file since there is some confidential information in it and making a new file all over again would take too much time :/ ListBox RowSource is pulled from table named "Employees", that table is located at Sheet2. I would prefer not having "search" button, but instead making TextBox as Change/AfterUpdate event. What I'm trying to achieve is something like in this video, but also for numbers, not just strings: https://youtu.be/PVIAIAQO_2I?t=34

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Use TextBox as search in ListBox (string or number)

    making a new file all over again would take too much time
    Such is the cost of asking for free help.

    You can modify the code I provided to loop through your worksheet range looking for matches, in the same way my code looks for matches in the listbox. Here is the idea:
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 11-08-2021 at 11:25 AM.

  9. #9
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Use TextBox as search in ListBox (string or number)

    Thank you anyway for trying to help me. Appreciated.

  10. #10
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    56

    Re: Use TextBox as search in ListBox (string or number)

    For anyone wondering, I've managed to find the solution:
    Please Login or Register  to view this content.
    Last edited by Pojzon; 11-10-2021 at 10:35 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Search listbox through textbox
    By ruud1957 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-14-2021, 03:36 AM
  2. [SOLVED] Filter Listbox or Search Listbox using Textbox
    By crowmagnus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2020, 08:34 AM
  3. Search files on Listbox with a Textbox
    By yinkajewole in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-03-2019, 02:46 PM
  4. Search within a ListBox as you type in a TextBox
    By shreeparas in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 02-20-2019, 10:10 AM
  5. textbox search for listbox with an array
    By Wornout8 in forum Excel General
    Replies: 3
    Last Post: 10-09-2017, 05:16 PM
  6. Search listbox from textbox
    By zplugger in forum Excel General
    Replies: 12
    Last Post: 08-23-2012, 08:11 PM
  7. [SOLVED] Textbox to search listbox
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2012, 08:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1