+ Reply to Thread
Results 1 to 18 of 18

Textbox search and display results in listbox

  1. #1
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Unhappy Textbox search and display results in listbox

    Hi all,

    First let me say I have posted this question on another forum but have not gotten any luck so far...link. I have simplified my file so that only the information needed is included; hopefuly this may clear up some of the confusion and allow me to explain my end goal better.

    I have a userform with a textbox, listbox, and commandbutton. The user enters text in the search box, clicks the commandbutton, and the results are displayed in a 3 column listbox. The search is done with wildcards. The column searched for the text entered in the textbox is column B. If a cell under column B contains the text that was searched, the B column cell, corresponding A column and C column cell will be displayed in the listbox in A | B | C order.

    I have attached the sample workbook. If the user enters "Radio" the results should be as such.

    Allan Radio Broadcasting, HTML, Marketing No
    Alston Talk Radio Not Interested
    Blankenship Desktop Support, Radio cards Not Interested
    Burdick Cross Domain, Radio Broadcasting No
    Carter Information System, Radio Tester No

    I have tried numerous sample codes and have been stuck on the problem for a week. Any help or code tries is very much appreciated - I would hate to have to scrap the search function because I couldn't figure it out. If anything else needs to be explained please let me know! Thank you all!!
    Attached Files Attached Files
    Last edited by AirBrun; 02-14-2011 at 11:55 AM.

  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: Textbox search and display results in listbox

    Why have you set your workbook to resize the Excel Window? You should warn people - they may not all realise what has happened.
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Textbox search and display results in listbox

    Sorry about that, I thought I had removed that code - guess not. Workbook is re-uploaded with the code removed - sorry!

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

    Re: Textbox search and display results in listbox

    Try this

    Search criteria in TextBox *radio*
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Textbox search and display results in listbox

    RoyUK,

    Thanks for the help. The file seems to do what i am looking for, though is there a way to make it not alter anything on Sheet1?

  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: Textbox search and display results in listbox

    paste the filtered range to another sheet, or simply delete the filtered range
    Please Login or Register  to view this content.
    Last edited by royUK; 02-14-2011 at 01:00 PM.

  7. #7
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Textbox search and display results in listbox

    The code above shows every row instead of the ones with the search criteria in it. Or was I supposed to change something in the code you just provided? Sorry for the ignorance, I'm clearly a novice =/

  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: Textbox search and display results in listbox

    I was a little rushed earlier, try this
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Textbox search and display results in listbox

    Thank you so much for you help. I noticed a couple things wrong though.

    1. After the filter is applied and removed, the cells in the excel sheet resize and become much larger, is there a way to stop that?
    2. If I search for something and display the results, I would like the user to be able to type in another search and display those results. Currently whatever you type in after the first search displays the same thing as the first search.
    3. I have a clear button that executes "ListBox1.Clear". After the listbox is populated by the search function, the program breaks.
    4. If the search term is not found the code breaks.

    I don't want to seem demanding or that I am taking advantage of you kind help, I'm just not sure where to begin with these issues.

  10. #10
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Textbox search and display results in listbox

    I have since fixed the clear issue and the cell resizing issue. the other 2 are a mystery still
    Last edited by AirBrun; 02-14-2011 at 03:48 PM.

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

    Re: Textbox search and display results in listbox

    The code does not resize the cells

    I've added an error handler in case no results are found & a Clear button

    Here's the ne code
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-14-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Textbox search and display results in listbox

    Sorry for the late reply. But I just realized that I don't think using a filter would work. I need to be able to delete rows from the listbox and move the rows up/down. From what I have read, this isn't possible using row source. Is there a way to do it with a loop?

  13. #13
    Registered User
    Join Date
    06-21-2011
    Location
    Rouen, FRANCE
    MS-Off Ver
    Excel 2007
    Posts
    2

    Thumbs up Re: Textbox search and display results in listbox

    Hey !


    First : thanks a lot for this help. I have been browsing through so many forums before finding your answers !

    My little contribution : to make the list update automatically when typing the word or part of it there is 2 modification to make :

    1 - change :
    Please Login or Register  to view this content.
    and instead put :
    Please Login or Register  to view this content.
    ... by doing this : as soon as you type a letter, Excel will do a FilterData and update the list under.(the best would be to have something immune to letter case, upper case, lower case, whatever case)

    2 - change the auto filter criteria :
    Please Login or Register  to view this content.
    and instead put :
    Please Login or Register  to view this content.
    ... by doing this : you can input just a part of the word.

    ============
    ... I do have a little request though. Could you comment a bit your code ?
    I'm trying to adapt on my own program and I'm blocking a bit on the range definition, resize, specialcells, etc. (since I don't have exactly the same worksheet. I don't start on the second line, I have more columns and my total amount of lines may change).

    Many thanks !!
    Last edited by Chrisprols; 06-21-2011 at 09:20 AM. Reason: (1) put the code in [code] (2) changed the P¨rivate Sub name to become right by being TextBox1_Change and not CommandButto

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

    Re: Textbox search and display results in listbox

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

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

    Re: Textbox search and display results in listbox

    What would
    Please Login or Register  to view this content.
    achieve? You can't change a CommandButton

    There's not actually such an event
    Last edited by royUK; 06-21-2011 at 07:58 AM.

  16. #16
    Registered User
    Join Date
    06-21-2011
    Location
    Rouen, FRANCE
    MS-Off Ver
    Excel 2007
    Posts
    2

    Smile Re: Textbox search and display results in listbox

    I have it on my excel ...
    As soon as I get back on my computer I'll edit this post and add a screenshot.
    but, yes: it's working. I did manage to do it.

    UPDATE 1 : Ah ! Sorry !! ... I put the change event on the textbox. My bad !
    UPDATE 2 : Original message corrected. Sorry for the confusion.
    Last edited by Chrisprols; 06-21-2011 at 09:21 AM. Reason: rectification

  17. #17
    Registered User
    Join Date
    08-02-2012
    Location
    Gurgaon
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Textbox search and display results in listbox

    I have one listbox and one textbox. I want when every I write the any character into the textbox that will automatically select into listbox.
    For example.
    In listbox have value:
    Ramesh
    Suresh
    Mahesh
    Rohit


    And when I type R then it will be automatically highlited the name that start with "R".

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

    Re: Textbox search and display results in listbox

    Ask your own question, don't post in other member's posts

+ 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