+ Reply to Thread
Results 1 to 5 of 5

VBA userform, filter listbox value as the user type in the textbox

  1. #1
    Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    194

    VBA userform, filter listbox value as the user type in the textbox

    I have found a code from this forum made by haripopuri member (I'm sorry as I'm a new member, I'm not allowed to post a link in my post) like this :


    Please Login or Register  to view this content.
    I don't understand how it works, but anyway after I tried the code, the result is similar to what I'm expecting.

    But what I want is actually the userform has one TextBox and one ListBox.
    The ListBox I've already populated from a named range (already in a unique value) using ListBox Property "RowSource".
    For example, the ListBox (after populated) now show a list :
    Apple
    Apricot
    Approach
    Alpine
    April
    Aladin 100
    Aladin 200
    Breast
    Brown
    Bandit

    I want those list filtered as I type in the TextBox (update automatically).
    For example, when the first character I type in the TexBox is "a" (without apostrophe), then the ListBox show Apple, Appricot, Alpine, Aladin 100 and Aladin 200.

    When I continue put one more character "p", so now the TextBox value is "ap" , then the ListBox show Apple, Apricot, Approach
    When I continue put one more character "pp", so now the TextBox value is "app" , then the ListBox show Apple, Approach.

    If I backspace, deleting the "pp" then put character "L", so now the TextBox value is "al", then the ListBox show Aladin 100 and Aladin 200.
    (The filtering is something like when filtering a table in a sheet by using Text Filter option "begins with").

    If I delete all the character in the TextBox (so there is nothing there), then the ListBox show all the list value in the named range (default value).
    Then ff I type in the TextBox characater "b" (without apostrophe), then the ListBox show Breast, Brown, Bandit.

    So, what is the code to "trigger" the ListBox filtered by the value in the TextBox as the user type there ?
    Any kind of respond would be greatly appreciated.
    Thank you in advanced.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    8,803

    Re: VBA userform, filter listbox value as the user type in the textbox

    Change the named range to suit.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: VBA userform, filter listbox value as the user type in the textbox

    Quote Originally Posted by AlphaFrog View Post
    Change the named range to suit.

    Please Login or Register  to view this content.
    Thank you very much, AlphaFrog.
    You really saved my day

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    8,803

    Re: VBA userform, filter listbox value as the user type in the textbox

    You're welcome. Thanks for the feedback.

    Bonus filter: If you enter in the textbox *ri, it will filter the list for items that contain ri.

    Bonus filter2: Enter ??p and filter the list for the 3rd character p.
    Last edited by AlphaFrog; 11-04-2018 at 02:28 PM.

  5. #5
    Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: VBA userform, filter listbox value as the user type in the textbox

    Quote Originally Posted by AlphaFrog View Post
    You're welcome. Thanks for the feedback.

    Bonus filter: If you enter in the textbox *ri, it will filter the list for items that contain ri.

    Bonus filter2: Enter ??p and filter the list for the 3rd character p.
    Nice and thank you for the bonus filter.
    I will remember your bonus filter in case one day I need to do that

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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