+ Reply to Thread
Results 1 to 12 of 12

Excel search box with VBA

  1. #1
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Excel search box with VBA

    Hi guys,

    I have some knowledge of excel macros but what I am attempting to do I don't even know where to start with, so I was hoping you guys could help

    I've got a spreadsheet with a worksheet that has about 1500 accounts on, 1 per line, and the columns are 'account number', 'account name', 'yearly sales' etc..

    On another tab there is a space for an account number to be added and the sheet gets populated, in an easy to read fashion, so that sales reps on the road can see a snapshot of that accounts info..

    I want to change this to make it more user friendly..

    I would like a button called 'open' and when you click on it a box pops up where reps could either enter an account number and bring up an accounts details or start typing in the account name and it starts auto populating with what it thinks the account you're looking for is (because most of the time you don't know off the top of your head what the account number is).. The accounts in question are pubs so their are going to be a lot of red lions and three horseshoes etc which may make this more problematic..

    Firstly is this possible and what's the best method of doing it??


    Sorry that there's not any more info I can give..

    Hopefully someone out there can help me


    Cheers,

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Excel search box with VBA

    1. I would use a Userform.

    2. I would use a Tab rather than a button to open the Userform.


    I will create something to get you started and then you can come back with a more detailed requirement.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Re: Excel search box with VBA

    Thanks Mehmet..

    I'll look forward to your reply. Once you get me started the rest of it should hopefully start making sense. It's all part of the learning process ...

  4. #4
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Re: Excel search box with VBA

    Hi Mehmet,

    Just had a brief look at userforms..

    The one thing that's stumping me is, say I design the userform with a Text box for account number and text box for account name.. I want to search for 'The Crown' and there are 5 crowns in the list of accounts. I want it to then bring up all those 5 options so I can click the one I want (haven't the foggiest how this can be done)...

    I assume the userform will sit in one tab and once I add an account number or account name, a macro will run which will populate all the relevant fields in another tab and switch me directly into that tab..


    Cheers,

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Excel search box with VBA

    You could do your search via cascading comboboxes - they drill down each related subject.
    As per file attached.
    torachan.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Excel search box with VBA

    Ok. I got distracted big time.

    I could not get the middle combobox working as I want but I will revisit that tomorrow.


    Click on "Open" at the bottom of excel to open the userform.

    Type B and then U in the first text box........ You get a list of all counties starting with a B and then just Buckinghamshire in Combobox1.

    Click on Buckinghamshire. Combobox2 will list all the towns in Buckinghamshire. I really want the dropdown to open but it does not at this point.
    I will write the code to filter the data using the second text box.

    Finally type r in the third text box. Your list shows all pub names starting with an r.

    type C in the fourth textbox and Your list shows all pub names starting with an r but also containing an C.

    Click on "Rose & Crown"
    Attached Files Attached Files
    Last edited by mehmetcik; 01-26-2021 at 08:41 PM.

  7. #7
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Excel search box with VBA

    Another option:
    Here's an example of data entry using userform + searchable listbox.
    It's not what you want but if you're interested in this method I can amend it to suit your requirement.

    How it works:
    - Double-click a cell in the table (where you want to insert data) to open the userform.
    - In any texbox you can type some keywords to search, e.g "ma la", the listbox will show all matching data.
    - Use Down Arrow or Tab to move the cursor to the Listbox.
    - Hit Enter or double-click to insert the selected data into the active cell.
    - To continue entering data to the next cell press Alt+Down arrow OR hit NEXT button (or press Alt+Up arrow OR hit PREV button to enter data in the previous cell)

    data entry via listbox 2a.jpg

  8. #8
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Re: Excel search box with VBA

    Hi guys,

    Thanks for all your help..

    All alternatives will work well but I think Mehmet's fits the bill on what I want to achieve..

    What I'd like is the same userform with the three text/combo boxes..

    The first combo/textbox linking to Account Names, the second combo/text box linking to Postcodes and the third combo/text box linking to 'account number..
    with 'OK' and 'Cancel' buttons also.

    So this pops up and a user can either enter an account number and press OK.. The account number is then populated on sheet 'name of cust' in cell 'A4' and an already written macro called 'Go' is automatically run, which brings up all that accounts info in a record card.

    Alternatively a user can enter account name and then go to combo box 2 and have a choice of postcodes that match the name of that account. There may be 5 Royal Oaks but the account manager will know the location of the one he wants and know what postcode matches..

    Once the correct postcode is picked from the dropdown then the account number automatically populates into the final text box and you click 'OK' and voila..


    I've had an attempt this morning with no real success, unless I sit down for hours and learn this stuff (which I will do) I'm going to struggle to get this done by the deadline of tomorrow...


    If it's an easy change to what you've already sent Mehmet


    Cheers,

  9. #9
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Re: Excel search box with VBA

    Hiya,

    I realised that the first solution was actually more what I was looking for, so I've had a go and have uploaded what I've done, with all sensitive material changed.

    The problems I've got:

    1: I can't change the first combo box to be Account Names, same with 2nd and 3rd combo boxes..
    2: Once account number is picked then pressing OK should fill cell C4 with the actual account number and then automatically call the go sub..


    any help would be appreciated..
    Attached Files Attached Files
    Last edited by purpleozzie; 01-27-2021 at 09:13 AM. Reason: Forgot to upload

  10. #10
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Re: Excel search box with VBA

    Anyone .....

  11. #11
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Excel search box with VBA

    Attached your file - combos are now working - you will have to put the code back on the two command buttons - then sort out what you are trying to do ???
    For the combos to work the data has to be formatted as 'text' because the process works by 'splitting strings'.
    torachan.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    06-08-2015
    Location
    Bristol
    MS-Off Ver
    2013
    Posts
    75

    Re: Excel search box with VBA

    Hi Torachan,

    Thanks for your reply..

    Is there another way of doing it apart from splitting strings as formatting the order number as text means that other formulas stop working?


    Cheers,

+ 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: 18
    Last Post: 05-15-2018, 05:17 AM
  2. VBA Excel Google Search Address and Pull First Search Result
    By senker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2017, 11:21 PM
  3. Replies: 2
    Last Post: 02-21-2017, 04:14 PM
  4. [SOLVED] Code to search Excel and return results even if part of search text is present
    By Taoyuan00 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2016, 09:20 AM
  5. [SOLVED] Search box in Excel to search key words in sentences in multiple worksheets
    By fernandoii676 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2012, 01:42 PM
  6. Replies: 2
    Last Post: 10-19-2012, 11:11 AM
  7. [SOLVED] How do I search excel spreadsheets using multiple search criteria.
    By Kasper in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-14-2005, 08:30 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