+ Reply to Thread
Results 1 to 4 of 4

How to sort a Dictionary or ComboBox?

  1. #1
    Registered User
    Join Date
    03-20-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    11

    Question How to sort a Dictionary or ComboBox?

    I'd like to sort some data alphabetically. The data is in a column, and as it's pulled in to the VBA program(?), it's stored in a Dictionary. Once the data has been pulled in, then the combobox is populated with the data from the Dictionary.
    The data is text, and the column of data has repeating elements and blank cells. Copying it into the Dictionary removes the duplicates and blanks, but leaves me with something out of alphabetical order. The data is copied into the key field, and the item is 0. The code is based on code I found here: https://stackoverflow.com/questions/...83188#28483188 See below for what is in use now.
    I am working with Excel 2016

    I see a lot of people online asking how to sort things in Dictionaries, comboboxes, etc. I don't see much of the same code, nor even the same kind of code. Code posted more than a few years ago seems to have disappeared. I find it surprising there are no built-in sorting functions.
    For example, this question http://www.excelforum.com/excel-prog...ictionary.html has a lot of code, most of which is difficult to read.
    I've seen several people link to this page: http://spreadsheetpage.com/index.php..._unique_items/, but I don't know how a list is related to a Dictionary or Combobox.
    The author of the code from the parralel dimension says that it returns an ArrayList, which is an object in java, but I don't know if he's using casual speech, or if that is an object name or object type: https://www.mrexcel.com/forum/excel-...lications.html
    I came across this post, but again, the code is completely different than anything else. https://www.codeproject.com/tips/814...-integer-value

    I will be sorting less than 1000 entries, so I don't necessarily need superlative Big O.

    I am hesitant to build my own sort because its been a while since I did that in Java class, and I still don't know much about VBA. I'd rather not have to build or debug a sort algorithm either.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to sort a Dictionary or ComboBox?

    ArrayList is also an object in .NET and is available in VBA, see here.

    Note, to use it for what you want you would probably need to extract the values in the dictionary to an ArrayList object.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to sort a Dictionary or ComboBox?

    A dictionary doesn't have an order like a collection. Help will tell you that the order of keys is not necessarily the order in which they are entered.

    You can certainly sort a combobox after it's loaded:

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How to sort a Dictionary or ComboBox?


    Hi !

    Can use too SortedList object instead of Dictionary object …

+ 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. How to Sort Combobox
    By hkbhansali in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2016, 05:09 AM
  2. [SOLVED] Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-12-2016, 08:28 AM
  3. Storing a Dictionary into a Dictionary Object
    By pago_boss in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2015, 03:04 AM
  4. Dictionary - Using a dictionary of dictionaries to hold individual orders
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2015, 08:32 PM
  5. [SOLVED] Create unique list using Dictionary Object in Combobx 2 based off selection of Combobox 1
    By escobf in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-12-2013, 01:27 PM
  6. Filter and Sort Scripting Dictionary
    By Jbryce22 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-16-2012, 03:34 PM
  7. Sort with combobox
    By Abaauw in forum Excel General
    Replies: 4
    Last Post: 02-06-2012, 12:17 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