+ Reply to Thread
Results 1 to 12 of 12

Remove Duplicated items in combo box

Hybrid View

FRIEL Remove Duplicated items in... 08-27-2008, 05:15 AM
Cheeky Charlie Hi, I think the answer is not... 08-27-2008, 05:16 AM
FRIEL hmm ok that sounds good ... 08-27-2008, 05:20 AM
dominicb Good morning FRIEL John... 08-27-2008, 05:29 AM
FRIEL thanks ill go check it out... 08-27-2008, 05:32 AM
Cheeky Charlie How's this? sub populate... 08-27-2008, 05:39 AM
norulen Re: Remove Duplicated items... 12-03-2012, 04:26 PM
FRIEL used this Private Sub... 08-27-2008, 06:08 AM
dominicb Hi FRIEL Have a look at... 08-27-2008, 06:39 AM
FRIEL yea thats good ive played... 08-27-2008, 06:55 AM
dominicb Hi FRIEL I'd probably... 08-27-2008, 07:13 AM
FRIEL thanks guys!! i used this... 08-27-2008, 07:16 AM
  1. #1
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266

    Question Remove Duplicated items in combo box

    i have a combo box in a form from a list of customers

    eg

    Aston Martin
    BMW
    BMW
    Jaguar
    Jaguar

    ect.

    i want to remove the duplicated entries

    so out of the 4 id have

    Aston Martin
    BMW
    Jaguar

    the reason for this is that there maybe more than 1 contact in any particular company.

    then i want a seperate combobox with all the contacts fot the selected company in it

    this will in turn fill in my form
    but i think i can do that bit

    hope you guys can help
    I dont like to use code i dont understand
    it makes it hard to use in other situations
    so please try to be as clear and patent as possible with me

    Criticism is welcomed

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Hi, I think the answer is not to remove the duplicates but instead only to insert unique entries.

    Code you post the code which populates your combobox?

  3. #3
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    hmm ok that sounds good

    thats the kinda thing i ment
    (not too good with words lol)

    Private Sub UserForm_Initialize()
    
    'sort into order
    'by customer
    'then contact
    
        Sheets("Customer Contacts").Activate
        Cells.Select
        Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("D2") _
            , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
            False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
            :=xlSortNormal
        Sheets("customer Contacts").Cells(1, 1).Select
        Sheets("purchase orders").Activate
         
    'populate
    For i = 2 To Sheets("customer Contacts").UsedRange.Rows.Count + 1
    
    
    ComboBox1.AddItem (Sheets("customer Contacts").Cells(i, 1))
    Next i
    
    End Sub

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning FRIEL

    John Walkenbach provides a solution to this on his site here. The code supplied also puts all the items in alphabetical order as well, but you can strip this out if you want. I find that using Collection objects are an excellent (and rapid) way of removing duplicates from an array as it doesn't require multiple looping. There is also a demonstration workbook to download.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  5. #5
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    thanks ill go check it out and ill let you know how it goes

  6. #6
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    How's this?
    sub populate
    Range(Range("A1"), Range("A1").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("P1"), Unique:=True
    UserForm1.ComboBox1.RowSource = Range(Range("P2"), Range("P" & Rows.Count).End(xlUp)).Address
    UserForm1.Show
    end sub
    I used column P (fairly arbitrarily) to create a unique filter of column A which I then used as rowsource for your combobox.

    HTH
    Last edited by Cheeky Charlie; 08-27-2008 at 05:40 AM. Reason: code tags

  7. #7
    Registered User
    Join Date
    12-03-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Remove Duplicated items in combo box

    Quote Originally Posted by Cheeky Charlie View Post
    How's this?
    sub populate
    Range(Range("A1"), Range("A1").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("P1"), Unique:=True
    UserForm1.ComboBox1.RowSource = Range(Range("P2"), Range("P" & Rows.Count).End(xlUp)).Address
    UserForm1.Show
    end sub
    I used column P (fairly arbitrarily) to create a unique filter of column A which I then used as rowsource for your combobox.

    HTH
    Superb Code Worked Really well for me

  8. #8
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    used this
    Private Sub UserForm_Initialize()
    Dim ND As New Collection
    
    'sort into order
    'by customer
    'then contact
    
        Sheets("Customer Contacts").Activate
        Cells.Select
        Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("D2") _
            , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
            False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
            :=xlSortNormal
        Sheets("customer Contacts").Cells(1, 1).Select
        Sheets("purchase orders").Activate
         
    'populate
     On Error Resume Next
        For i = 2 To Sheets("customer Contacts").UsedRange.Rows.Count
            ND.Add Sheets("customer Contacts").Cells(i, 1).Value, CStr(Sheets("customer Contacts").Cells(i, 1).Value)
    '       Note: the 2nd argument (key) for the Add method must be a string
        Next i
        
        x = 1
        For Each Item In ND
        ComboBox1.AddItem ND.Item(x)
        x = x + 1
        Next Item
    
    End Sub
    any ideas on how to do the second part??

    i need to say select bmw
    and for a second combo box to have the different contacts in it

    i think this is going to be the hard bit

  9. #9
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi FRIEL

    Have a look at this workbook with an example userform. I have only done it very simply, so no doubt there are going to be some changes needed, but hopefully it will point you in the right direction.

    HTH

    DominicB
    Attached Files Attached Files

  10. #10
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    yea thats good ive played with it n got it to go with what i need
    thanks allot

    is there a way to reference to a row that the second (contact) value comes from??

    as i have numbers and emails on the same row i want to fill in on the form into textboxes

  11. #11
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi FRIEL

    I'd probably stick with the little table, and have a seperate table that lists all your contacts vertically, and their contact details going across. You can read the contents of the combobox like so :
    c=ComboBox2.Value
    and then perhaps retrieve all the pertinent information using VLookUp.

    HTH

    DominicB

  12. #12
    Forum Contributor FRIEL's Avatar
    Join Date
    03-07-2008
    Location
    Coventry
    MS-Off Ver
    2003 and 2007
    Posts
    266
    thanks guys!!

    i used this
    to use find the row

    a = 2
    Do While Sheets("Customer Contacts").Cells(a, 1).Value <> ""
    If Sheets("Customer Contacts").Cells(a, 1).Value = ComboBox2.Value Then
        If Sheets("Customer Contacts").Cells(a, 4).Value = ComboBox5.Value Then
            GoTo 1
        Else: End If
    Else: End If
    a = a + 1
    Loop
    1:

+ 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. Inputting items into a Combo Box
    By Zboy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2008, 12:25 AM
  2. Combo Box - Display Unique Items in List
    By Gary S in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2007, 11:15 AM
  3. Adding same items to more than one combo box
    By SOS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2007, 07:18 AM
  4. How to reset the combo boxes (remove selected values)
    By Richard Flame in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-11-2007, 02:29 PM
  5. remove items from list box (sorry it`s a bit long)
    By bahadirakcan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2006, 08:11 AM

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