+ Reply to Thread
Results 1 to 11 of 11

Search Results displayed in a Listbox

  1. #1
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Search Results displayed in a Listbox

    Hi everyone,

    I've got a listbox set up on a userform with one textbox. What I need to happen is that the moment the user types in something into the textbox, a search is made in a worksheet using those characters. When a match is found, the first 11 columns of that row be displayed in the listbox. The search then continues to search the sheet to find additional matches and lists those rows if found.

    The problem is that the listbox should empty and update with each character change. So I guess the VBA code with have to sit in the textbox_change sub.

    What I am trying to achieve here is a list of results that are narrowed down the more the user types. They would then be able to double click the line they need in the listbox to go to a userform with more details about it.

    Can anyone please help me with this? I am not quite sure how to search and list results in this way.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Search Results displayed in a Listbox

    See the DatabaseForm example
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    Quote Originally Posted by royUK View Post
    Thanks Roy, I'll take a look. Can't download anything right now though until I get home.

  4. #4
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    I had to put this to the side temporarily so sorry for picking up again.

    The example you gave link to was close to what I was after. In the end I am toying with the following code i found here

    But now I have a further problem. I keep getting an error message saying "Could not set the list property. Invalid property value". The following line highlighted is

    Please Login or Register  to view this content.
    I am using a 2 column listbox. The characters entered in textbox 1 should _change trigger the search to look in range I2:I797 and list all matches in column 2 of the listbox with column one displaying column G of the corresponding row for each result.

    My code so far is:

    Please Login or Register  to view this content.
    Can anyone please help me?

  5. #5
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    Something I discovered which has helped me a little as it was causing a slight conflict - I removed the following code from the userform initialize sub:

    Please Login or Register  to view this content.
    The reason I had that code in was that I wanted the list in its entirety to be visible in the listbox. As it's quite a long list (and not in any particular alphabetical order), my intention was to have the list in full to begin with and the results narrowing the more the user typed in the textbox. It's not essential if this code has to go completely.

    However even despite removing this completely I'm still running into error messages. And it appears I'm only ever getting one result back in the listbox whatever I type in.
    Last edited by Julesdude; 02-25-2011 at 04:29 PM.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Search Results displayed in a Listbox

    You can't use the List property like that
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    Thanks Roy, Your code prevented the error message, but now as I type in the textbox, no results are listed at all and I'm not sure why. Any found results should be listed from the specified range in column 2, and in column 1 the respective value in same row but column G.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Search Results displayed in a Listbox

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  9. #9
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    Certainly, here you go.
    Attached Files Attached Files
    Last edited by Julesdude; 02-28-2011 at 11:26 AM.

  10. #10
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    Quote Originally Posted by Julesdude View Post
    Certainly, here you go.
    Not sure why the above file is that large but anyway, it demonstrates the form I'm working with and accompanying code. I just can't get it to bring up what I need - a list of strings in the specified range which contain the characters entered in textbox 1.

  11. #11
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Search Results displayed in a Listbox

    Bumpety bump. Anyone able to help?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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