+ Reply to Thread
Results 1 to 20 of 20

creating unique items lists for comboboxes... need a better way

  1. #1
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    creating unique items lists for comboboxes... need a better way

    Still trying to learn how to explain what I need in a simple thread title, but here's my issue:

    I have code written that "works", but it's taking quite a while for my file to open and run through the "initialize" event code.

    The code does the following:


    1. Turns off screen updating
    2. Opens another source workbook from a network folder
    3. Copies 8 columns worth of data (about 6,000 rows, give or take) to Sheet4 on my workbook
    4. Closes the source workbook
    5. Renames and sets cell formatting on the 8 column headers (row 1, columns A:H)
    6. Applies an autofilter and filters the copied data based on column A
    7. Creates a list of unique values from each of 6 columns from Sheet4 on column A of 6 separate sheets, each containing a named dynamic range in column A.
    8. Sets focus on Sheet1 and turns on screen updating

    Sheet1 contains a userform which, upon opening, uses the 6 sheets of unique data to load the lists for 6 comboboxes. The comboboxes work in a reverse cascading fashion, where filling in the first will fill the remaining ones with the data that relates to the value entered in the first combobox, and if "n/a" is entered, then the focus moves to the next combobox in line and so on until either a job is selected or all boxes are filled with "n/a". I'm actually quite proud of the combobox functionality, as it's working exactly as I intended it to.
    My issue is that it's taking a LONG time for the workbook to open and initialize, presumably because I copied and modified the same section of code 6 times to perform operation "7" above... I couldn't figure out a better way of getting the combobox lists loaded with only the unique data and no repeats.


    I have attached my file in its' current state, with the portion of code that opens and references the second file neutered with (') marks... the data is already loaded, other than that the sample file should run the same for you as it does for me.

    The code I have so far is below, please take a look and see if there's a better, more efficient way of getting to the end result I have here. Thanks a bunch!

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    Use Dictionary to generate unique lists.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    This should improve things.
    Please Login or Register  to view this content.
    The reason your userform takes so long to load is your function GetUserFullName.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    Thanks for the suggestion, bakerman2...

    I searched for using dictionaries to populate comboboxes, and found this snippet of code:

    Please Login or Register  to view this content.
    I will play with this code tomorrow, and try to modify it for my program.

    Would it be better to duplicate the code and create a separate dictionary for each combobox ("dict1", "dict2", and so on), or clear the dictionary and reload it with new keys for each of the comboboxes?

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    You probably missed Post#3.

  6. #6
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    Just saw your reply after posting mine... looks like you're using the dictionaries to create the unique list sheets, which does happen faster than my way. I was thinking that with dictionaries, I could bypass the need for creating those pages altogether, though. If the dictionaries can be created within the userform instead of the workbook itself, that could eliminate the need for those extra sheets entirely. I will try that tomorrow, and post my results. I think I can move a few lines around and apply autofilter before each dictionary is created to still end up with the lists sorted, too.


    Your help has cleared up many uncertainties I had regarding dictionaries, and is much appreciated!

  7. #7
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    Quote Originally Posted by bakerman2 View Post
    You probably missed Post#3.
    Yup, and post #5 while replying to post #3.

    Thanks again!

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    OK, then try this one.
    Attached Files Attached Files

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

    Re: creating unique items lists for comboboxes... need a better way

    Here’s another option:
    This is an example of a combobox that create a unique list and also can search as you type.


    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    Quote Originally Posted by bakerman2 View Post
    OK, then try this one.
    Code looks brilliant, better than what I was going to try for sure.

    I reactivated the code for pulling from the network file, and all is working as it should, but the button click event is throwing this error on the line "New_Entry.Show":


    Please Login or Register  to view this content.
    Nothing changed as far as the userform name, so I'd think it must be something within the userform code preventing it from opening. Any ideas?

  11. #11
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    Akuini, I like how your combobox works, but I see one flaw. If I type "Atlanta", the list is narrowed down to a single entry, "Atlanta, Georgia" as it should be, but if I hit enter with only "atlanta" typed into the box, the box value stays as "atlanta" and does not auto-complete to "Atlanta, Georgia". In my application, this would allow the user to enter an incomplete Job number which would break the system. Is there a change that could be made to that code that would get around that?


    * EDIT * - scratch that. I just tried it again, and couldn't get it to replicate that behavior. Hitting "enter" is now filling in the complete list entry as selected. I guess I'll chalk that up to a ghost in the system, LOL...
    Last edited by Arnold Layne; 03-13-2019 at 08:51 AM.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    Got to the Userform_Initialize code and loop through the code using F8. That way we can see on which line the error occurs.

    The import code seems nothing special to me I don't think it has something to do with it.

    It works fine in your example file for me so try to spot what's different from your current file and the example.

  13. #13
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    It seems to be erroring out on this line:

    Please Login or Register  to view this content.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    Read following link and see if you can work from there.
    https://www.ozgrid.com/forum/forum/h...tomation-error

    You can download Net Framework on following link.
    http://www.microsoft.com/en-us/downl...n.aspx?id=1639

    If no luck we can try something else.
    Last edited by bakerman2; 03-13-2019 at 09:43 AM.

  15. #15
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    I added the reference to "mscorlib.dll", but that didn't help. I am on a 64 bit Windows system, so that may be the issue based on some of the comments in the linked thread.

    Can the {CreateObject("System.Collections.ArrayList")} be changed to a dictionary instead of a collection and still do the same thing?

  16. #16
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    Dictionaries don't have a Sort method so additional code would be required to sort each dictionary, slowing down the flow.

  17. #17
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    Gotcha.

    But, if we apply an autofilter on each column of data before using that column to populate the dictionary, basically "pre-sorting" the data, then the dictionaries would be created in the right order... would that be a significant drain on resources?

    If so, I don't mind if the data in the dictionaries or the combobox lists are not sorted, as long as the separate code that adds "n/a" as an option still adds "n/a" at the top. The rest is pretty much irrelevant, as my users will be typing their entries based on the information they have on a hard copy printout in front of them anyway.

  18. #18
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    Worksheet interaction is never a good deal.

    Try file with unsorted dictionaries.
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: creating unique items lists for comboboxes... need a better way

    That seems to be working fine. Thanks a bunch, you've saved me hours of trial and error, if not days!

    I can't thank you enough!

  20. #20
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: creating unique items lists for comboboxes... need a better way

    Thanks for feedback and good luck with your project.

+ 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: 12
    Last Post: 11-07-2017, 10:30 AM
  2. [SOLVED] Picking Different Items Between Two Lists and Creating a New List
    By CWatsonJr in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-16-2015, 04:19 PM
  3. Dependent drop down lists without creating unique named lists
    By pajordan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 12:20 PM
  4. Creating Unique Lists
    By Trueman_86 in forum Excel General
    Replies: 16
    Last Post: 07-13-2010, 06:49 AM
  5. Combine two lists into a list of unique items
    By mkvassh in forum Excel General
    Replies: 4
    Last Post: 03-26-2010, 03:27 AM
  6. Duplicate and unique items in 2 lists
    By Vince in forum Excel General
    Replies: 0
    Last Post: 08-22-2006, 06:15 PM
  7. Creating lists of unique items
    By alexander in forum Excel General
    Replies: 2
    Last Post: 04-10-2005, 10:13 AM

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