+ Reply to Thread
Results 1 to 17 of 17

Auto predict Combobox

  1. #1
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Auto predict Combobox

    I am wanting to get auto-predict comboboxes in cells that have data validation lists. It is working for 2 out of 3 columns. I don't know why it's not working for all columns.

    I am basing this on https://www.contextures.com/xldataval11.html:

    1) Name the Lists
    Create names for the cells that contain the lists.
    If your lists are in named Excel tables, you'll need to create a second set of names.
    Otherwise, the combo box lists will be empty.
    - First, create the named ranges, based on the table columns:
    o Name the cells with day names as DayListA
    o Name the cells with month names as MonthListA
    - Then, create a second set of names, based on that first names.
    o Create a named range DayList, based on the name DayListA
    o Create a named range MonthList, based on the name MonthListA

    2) Create a Dropdown List
    The next step is to create the dropdown lists
    Cells B2:B12 have data validation lists with the source DayList.

    3) Add the Combo box

    4) Change the Combo Box Properties
    - Name the Combo Box
    - Change the Font and Font Size
    - Set the Number of Rows
    - Turn on AutoComplete
    o In the Properties window, click in the MatchEntry property.
    o From the dropdown list, select 1-frmMatchEntryComplete

    5) Add the Code

    VBA code:

    Please Login or Register  to view this content.

    Thanks!!
    Attached Files Attached Files
    Last edited by awoolfe; 05-05-2021 at 08:22 PM. Reason: Add codetag

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

    Re: Auto predict Combobox

    We can give you a answer when you have enclosed your code with 'code tags' as required by rulle #2.

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  3. #3
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Thanks torachan for advising how I put in the code tags.
    Looking forward to learning from others

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

    Re: Auto predict Combobox

    I had a brief look - more thought needs to be applied to establish what you are trying to achieve.
    The 'Client' validation is an O.K. approach as you are just ensuring single elements apply.
    However using data validation on individual elements of a multi-column/multi-choice table is not very productive.
    The table needs ordering by priority sort (key column first followed by filter order).
    Using data entry UserForm/VBA would allow you to produce an application that would be free of on-sheet formula and far easier to maintain.
    Attached is a file I use to demonstrate dependent comboboxes (only the relevant data to combo1 passes to combo2 etc., etc.,)
    Just a small tip when creating & populating tables, do not extend them beyond the last row/column of data, always separate each table by at least one blank column.(this prevents any remote likelihood of one table interacting with its neighbor - especially when you are filtering or sorting a table.
    The method of overlaying data validation with combos is more of a novelty than of any practical use.
    torachan.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Thanks for your reply and hints!! I haven't used user-forms before so an interesting concept. I am also very new to vba (this is my first attempt)

    The reason I was interested in the combobox was to be mainly to able to autopredict the answer based on the assigned data validation list. As the number of options increases it was taking more time to scroll and select the correct option. Also the font was small to read.

    The 2 columns I would ideally like auto-predict and larger font is the "Client" and " Description" column as there can be long data validation lists. I agree I don't need the autopredict on the "Item" column as it is a dependent list and there are only a few options.

    Is there a way to get user-forms to auto-predict from a set list (that is more extensive that what is in the table where the data is being added)? In your example, the user form options are based off the same table only and I'm not sure how to use it to add new data to the table.

    Thanks!

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

    Re: Auto predict Combobox

    A demo quickly thrown together incorporating your validation table.
    Just use the comboboxes in order (top to bottom) then 'SUBMIT' the data.
    That is just a small illustration of how clean UserForm data entry is (note: no on sheet formula to maintain)
    Your validation tables are 'elastic' (add/remove data the code will know the size of the tables).
    torachan.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Thanks for your answer. I do like how it is set out!

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

    Re: Auto predict Combobox

    follow-up, new file attached and annotated code listing.
    while testing after submission I was presented with a 'fluke' I had not encountered/anticipated in using Excel for 35 years (spreadsheets for 50+ years).
    The method I use for cascading combos entails the use of splitting arrays, in one of the columns of data the user had used 'commas'.
    The nett outcome had me 'scratching extremities' for what appeared to be an eternity before the 'penny dropped'.
    So proof that one is never too old to learn. So use anything as punctuation as long as it is NOT a 'comma', I have replaced them with '-'.
    torachan
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Thanks torachan for the effort you have put in! I was eagerly awaiting your post and now will go study it!

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

    Re: Auto predict Combobox

    updated file - adds funder to label caption for reference.
    type in first combo should bring up valid names - funder ref will clear if client is not valid.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    I have attempted to work the vba code into my spreadsheet. The red background column headings are what is included in the vba code. I am hoping to combine the vba code for the userform and my pre-exisiting excel formulas (otherwise I would need a 30 item userform).
    Can the userform vba run alongside the excel formulas in the cells that are left blank in the vba?

    It is coming up with error 9 - out of range which I haven't worked out where it's coming from. But I am hoping I am on the right track and not gotten myself bogged?
    Attached Files Attached Files

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

    Re: Auto predict Combobox

    you are making the process far too complex - there is no need for a single formula on your sheets.
    the default data is already present - it is simple process to filter that - there is no need for 30 more items on the userform
    coding will perform the operation all that is needed is an illustration of what needs to be saved where - put headings on you columns and dummy data in the cell to show what you need.
    putting it 'politely' your tables are a mess, they need to be ordered - no blanks - no missing rows - no missing columns.
    the error is caused by trying to load a table that does not exist - you have altered all the referencing and you have no sheet3 in your file - look at my original.
    If you want me to take a second look, the first step would be to extend the headings of my Client_Treatment sheet so that I know what you want to record, once I have that I can show how it is possible to record your data without using formula or extra fields on the userform.

  13. #13
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Fair call re the complexity and mess! After playing around with the code and simplifying my spreadsheet the code is working well. Thankyou!!

    My only question now is:
    Is there a way to link the label "Funding Reference" to automatically populate ComboBox1 FUNDING?
    If I am asking others to manually populate the FUNDING combobox, I can see errors occurring with the wrong option selected.

    Or if I change ComboBox1 FUNDING to a label as there is only one correct answer, is there a way I can link the new label to ComboBox2 DESCRIPTION? There will still be multiples possibilities here.

    Thanks!!

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

    Re: Auto predict Combobox

    If your default list that loads ComboBox1 is setup as per my example file there is noway that anyone making choices using the series of ComboBoxes can make a wrong choice.
    In the file attached I have overlayered the comboboxes with a label - this prevents anything been typed into the combobox so the choice is only that from the default list.
    If still unclear post your file and I will edit it to demonstrate as required.
    torachan.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Thanks. I see what you are doing. I'm not so much worried that they will write the wrong thing. But they will select the wrong thing from the list. I also want to automate as much as I can to make it easy.4.jpg

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

    Re: Auto predict Combobox

    see if the attached does what you want.
    there is a full width label covering the funding combobox.
    the value from this combobox forms the start value for loading the filtered list to the next combobox.
    as there are payer in the client list that have no funder cross reference an error message box appears and no entry can be made until corrections made.
    torachan.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    01-12-2021
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    118

    Re: Auto predict Combobox

    Perfect!!! Thankyou

+ 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. [SOLVED] Combobox auto-predict dropdown list
    By awoolfe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2021, 10:54 PM
  2. Replies: 16
    Last Post: 04-26-2018, 04:18 AM
  3. [SOLVED] Auto close combobox
    By ericbartha in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-04-2016, 06:19 PM
  4. [SOLVED] Code required to Auto Populate 3rd Combobox based on 02nd Combobox Selection
    By bimmy80 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-14-2015, 03:56 AM
  5. Auto Drop Down ComboBox
    By BLS99covert in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2014, 05:49 AM
  6. Combobox auto update
    By trenars in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-09-2012, 12:38 PM
  7. auto filter with combobox
    By KVandal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2007, 04:16 PM

Tags for this Thread

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