+ Reply to Thread
Results 1 to 8 of 8

Find as you type in listbox control - solution for multi-column listbox - vba dictionary

  1. #1
    Registered User
    Join Date
    04-19-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    87

    Find as you type in listbox control - solution for multi-column listbox - vba dictionary

    hi

    I have the following code courtesy o jindon from an old thread (2011) at the Mrexcel forum. It works well for a listbox containing only one column, but i need it for a three column listbox. i would appreciate some help as i dont know much about dictionaries.

    I have three columns of data and i want the three items for any matched rows to be returned to the listbox.

    Userfilter is the name of the textbox on the form where the user enters a string to search and filternames is the name of the listbox where results are returned.

    I prefer this dictionary approach as its alot faster than an array solution i tried.

    thanks

    Please Login or Register  to view this content.
    In the sample file, id like to see the company ID, name and location in the listbox. Click the blue button on the first sheet to launch the form. thanks

    Sample file attached : Dict.xlsb
    Last edited by wazimu13; 12-08-2014 at 10:02 AM.

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    Try something like this:-
    Please Login or Register  to view this content.
    Regards Mick

  3. #3
    Registered User
    Join Date
    04-19-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    hi, thanks for the reply. However this doesnt seem to work, and when i step through the code its not adding anything to the dictionary even when i enter the first letter of a word i know is on the list. The code from "if dic.exists(userfilter.value)" onwards is not processed. Perhaps im missing something? cheers

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    From your description, the code I sent does the following:-
    You place a value in Userform (From column "B" of sheet Customer) like "Mychef" and the userform list box returns Columns 1 to 3 for the Row which has that name.
    Perhaps you want something else ????
    Attached Files Attached Files

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    a slightly different version
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-19-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    @MickG - i see what you mean . For your code to work, the user has to type the whole word eg "Mychef". In this case what i would like is similar to what the first code i posted did, which was update the listbox after each keystroke. So in the "Mychef" example, as the user types "M", every company name with M in its name is returned, and with further keystrokes the list is filtered further. cheers

  7. #7
    Registered User
    Join Date
    04-19-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    @nilem - hi, thanks for contributing. Your code works after the following slight modification:

    Please Login or Register  to view this content.
    I found that without those, the user has to use the correct case to search otherwise no or incorrect results are returned. I tested by typing "m", a letter which all 3 companies share, but only "Pethomes" was returned as its the only one with a lowercase m.

    Many thanks

  8. #8
    Registered User
    Join Date
    10-08-2018
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2010
    Posts
    1

    Re: Find as you type in listbox control - solution for multi-column listbox - vba dictiona

    Hey nilem! Your code works perfectly! Is there a code that will allow duplicates of the data in a specific column like if Column B has two Company A but different datas in Columns C and D, how will the code show all the data?

    COLUMN B..........COLUMN C........COLUMN D
    ABC Inc..............123..................NYC
    ABC Inc..............234..................NYC
    ABC Inc..............345..................LA
    Last edited by shairabellax; 11-05-2018 at 03:55 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. Replies: 1
    Last Post: 01-07-2018, 04:13 PM
  2. [SOLVED] Multi column listbox
    By tradinup2 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-01-2013, 05:12 PM
  3. [SOLVED] Find Multi Selected Items in Listbox in Range
    By Sniper in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2012, 07:53 AM
  4. Combobox-listbox multi-type search
    By greekboyuk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2011, 03:47 AM
  5. Multi Column ListBox
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-12-2010, 02:39 PM

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