+ Reply to Thread
Results 1 to 10 of 10

How to alphabetize a collection that's already populated

  1. #1
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    How to alphabetize a collection that's already populated

    Hi all,

    If I have a collection that is already populated and the item and the Key are the same value, how can I alphabetize that collection? I don't want to use the method of putting the values in a worksheet, sorting it, then putting them back into the collection.

    For example, I have to get all the unique values in every sheet that is in range P18 so I'm using a collection so each value can only be added to the collection once.

    Please Login or Register  to view this content.
    At this point all unique values in P18 of every sheet are in the collection. How can I alphabetize that now?

    Thank you!

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: How to alphabetize a collection that's already populated

    There are VBA solutions out there for quicksorting a collection but it might be easier in this case to use the .Net SortedList object if you're on Windows:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: How to alphabetize a collection that's already populated

    Thanks WideBoyDixon!

    That works excellent! Thanks for that!

  4. #4
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: How to alphabetize a collection that's already populated

    WideBoyDixon,

    Well it works excellent on my computer, but not on another persons computer (which is a laptop that I know nothing about yet, but I'm getting Excel and Windows info)
    Anyway, the 2 attached files are the error he gets on his computer. Can you please help me find out why?
    Attached Images Attached Images

  5. #5
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,222

    Re: How to alphabetize a collection that's already populated

    I think SortedList requires Framework version 3.5, which is often not available on new computers. They generally have version 4.5 or later. But just install that version and you should be OK.

    Artik

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: How to alphabetize a collection that's already populated

    Quote Originally Posted by Artik View Post
    I think SortedList requires Framework version 3.5
    I could swear I remember Microsoft telling us that these kind of dependency problems would cease to exist when they introduced the dotNET "stuff" way, way back.

  7. #7
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: How to alphabetize a collection that's already populated

    Thanks you guys!

    Well if that's the case, I'm not going to be able to use this solution because I'm not going to be able to go around and check everyone's computers or install anything. It sure works good on mine though. I found another solution, but it separates Capitalized words from non capitalized words so that's not ideal, but I might have to use it.

    Thanks again!

  8. #8
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,222

    Re: How to alphabetize a collection that's already populated

    If the ASCII character range is enough for you then you can try it:
    Please Login or Register  to view this content.
    Artik

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to alphabetize a collection that's already populated

    Re: How to alphabetize a collection that's already populated
    1) Add below lines in bold
    Please Login or Register  to view this content.
    2) Add below sub procedure
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    01-02-2020
    Location
    Idaho, USA
    MS-Off Ver
    365
    Posts
    273

    Re: How to alphabetize a collection that's already populated

    Thanks Artik and Jindon!

    I will be trying these later, just wanted you to know. I will be back with an update either tomorrow or after the weekend (3 day weekend for me ). Thank you very much for your help here!

+ 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. Names Collection - Generating RefersToRange from RefersTo when RefersToRange not populated
    By MessEngineer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2019, 07:22 PM
  2. [SOLVED] When a collection created bring another column value into the collection
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-21-2018, 04:33 AM
  3. Replies: 4
    Last Post: 10-30-2015, 01:30 PM
  4. [SOLVED] Performance of iteration through Words collection degrades as collection gets bigger
    By 6StringJazzer in forum Word Programming / VBA / Macros
    Replies: 7
    Last Post: 01-14-2014, 09:44 AM
  5. Alphabetize List of Names Populated From Multiple Sheets
    By albizzundy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-04-2013, 05:43 AM
  6. Replies: 2
    Last Post: 12-23-2011, 11:04 AM
  7. Problems storing a Collection within a Collection. Is this possible?
    By Tarball in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2007, 10:47 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