+ Reply to Thread
Results 1 to 7 of 7

Sorting and removing duplicates in a Combobox

  1. #1
    Registered User
    Join Date
    01-22-2014
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    25

    Sorting and removing duplicates in a Combobox

    Hi,
    I've tried searching online for a solution and haven't found anything that doesn't give me all sorts of errors, so I'll ask.

    I have a userform which has a bunch of comboboxes. Several of these I want to populate from a column in the worksheet, and have them listed in alphabetical order and without duplicates and blanks.

    So far I've been able to populate the combobox without blanks, but I'm having trouble removing duplicates and sorting.

    Here's the code I'm using.

    Please Login or Register  to view this content.
    What can I add to this so that the duplicates are removed and the list is sorted?

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

    Re: Sorting and removing duplicates in a Combobox

    Your Code so far will work but it will be will very slow.

    If you have 200 000 rows of data then VBA will have to interface with Excel 200 000 times to read the data in each cell.

    You can achieve the same result without using a loop to read your cells into VBA.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 02-02-2017 at 04:37 PM.
    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
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Sorting and removing duplicates in a Combobox

    You can do all that work with arrays - but because it's all done in memory it's not so easy to see what the VBA is doing if something is not doing what you want.

    I prefer to create a new sheet to hold all the lists, getting VBA to remove empty cells and duplicates before sorting and naming them.

    Do you require the lists to be dynamic?
    - will the data in various columns change over time
    (so that the alphabeticized, de-duped, de-blanked list needs a regular refreshing?)
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Sorting and removing duplicates in a Combobox

    Try this

    Please Login or Register  to view this content.
    Missed the sorting part. But this should do

    Please Login or Register  to view this content.
    Last edited by mike7952; 02-02-2017 at 02:56 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Registered User
    Join Date
    01-22-2014
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    25

    Re: Sorting and removing duplicates in a Combobox

    Thank you Mike!! The second part worked flawlessly.

  6. #6
    Registered User
    Join Date
    01-22-2014
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    25

    Re: Sorting and removing duplicates in a Combobox

    One more question. If I wanted to do the same thing for several other comboboxes on the same form (linked to different columns of course), how would I go about that. I tried just copying and pasting that code within the same sub and changing the column letters and combobox name, but it gives me errors.

  7. #7
    Registered User
    Join Date
    01-22-2014
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    25

    Re: Sorting and removing duplicates in a Combobox

    Never mind. I figured out my mistake. The cell values needed to be text.

+ 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] Removing Duplicates In A VBA Userform Combobox?
    By BDBJ1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2016, 07:50 AM
  2. [SOLVED] Appending, sorting and removing duplicates of chunks of data per column
    By terryhenderson in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-10-2015, 08:34 AM
  3. Sorting based on one column values and removing duplicates!
    By devpp in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-26-2013, 09:41 AM
  4. Excel 2007 : Removing Duplicates without sorting
    By mohit rawat in forum Excel General
    Replies: 2
    Last Post: 06-14-2012, 03:11 AM
  5. Replies: 6
    Last Post: 03-29-2012, 12:16 AM
  6. sorting combobox values & no duplicates
    By Mamud in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-18-2011, 01:38 PM
  7. Removing Duplicates from ComboBox and Populating one combobox based on another
    By kbmtech in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2010, 11:17 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