+ Reply to Thread
Results 1 to 6 of 6

User Form to search multiple columns

  1. #1
    Registered User
    Join Date
    05-02-2009
    Location
    Eagan, MN
    MS-Off Ver
    Excel 365
    Posts
    58

    User Form to search multiple columns

    I am trying to make the user form in the attached file search column "C" and "E" and return the values I currently have in the listbox. I can search column "E" just fine but when I expand the search to include "C" I get a run-time error and the list box is empty.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: User Form to search multiple columns

    I would recommend you keep the search clean, add another search textbox to your form called Tire Size. Set a TextBox_change event for both so if you type in one box, it clears the other.

    Then when you click FIND, have it run a different macro based on which of the two search boxes is filled out.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-02-2009
    Location
    Eagan, MN
    MS-Off Ver
    Excel 365
    Posts
    58

    Re: User Form to search multiple columns

    Quote Originally Posted by JBeaucaire View Post
    I would recommend you keep the search clean, add another search textbox to your form called Tire Size. Set a TextBox_change event for both so if you type in one box, it clears the other.

    Then when you click FIND, have it run a different macro based on which of the two search boxes is filled out.
    I have never done a TextBox_change, how would I set that up?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: User Form to search multiple columns

    Did you create this form?

    First, open up the form in the VBEditor and add the second Text Box and label below the first (label Tire Size).

    Then double-click the new Text Box and it will pop open the TextBox3_Change window.
    Put in code like this:
    Please Login or Register  to view this content.
    This instructs that ANYTIME a change occurs in textbox3, change the value of textbox1 to nothing.

    Now, back on the form, doubleclick the Textbox1 and do the same thing in reverse:
    Please Login or Register  to view this content.
    From there, add an IF/THEN to the beginning of your FIND button macro to see which textbox has a value.
    Please Login or Register  to view this content.

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

    Re: User Form to search multiple columns

    This example could be adapted for whay you want.It displays the data in a listbox which can then be filtered.

    FilterForm.zip


    I can't really see why you need to use VBA, AutoFiltering the sheet should be good enough.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    05-02-2009
    Location
    Eagan, MN
    MS-Off Ver
    Excel 365
    Posts
    58

    Re: User Form to search multiple columns

    JBeaucaire - I could not get this to work properly. Running it with the IF/Then leaves the lower list box that shows all the matching information empty.

+ 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