+ Reply to Thread
Results 1 to 2 of 2

adding into combo box and removing duplicates

  1. #1
    Abhay Sanan
    Guest

    adding into combo box and removing duplicates

    i have a list in my spreadsheet which needs to be added to my combo box
    list. The problem is that there are repeated number of these values. This is
    the code I have written but it does not work as i need it to. Not all the
    values have been added into the list. Also for every letter i type in the
    combo box this function is called making it slow. If some1 could correct it,
    it would be great. Thanks!

    Private Sub ComboBox1_Change()
    Dim i As Integer
    Dim j As Integer
    Dim count As Integer
    Dim entry As String
    Dim check As String

    Range("C8",Range("C8").End(xlDown)).Select
    count = Selection.Rows.count

    Worksheets("Portfolio").Range("DR11")=count
    For i = 8 To count
    entry = Cells(i, 3).Value
    ComboBox1.AddItem (entry)
    Next i

    For i = 8 To count
    entry = Cells(i, 3).Value
    For j = i + 1 To count
    check = Cells(j, 3).Value
    If entry = check Then
    ComboBox1.RemoveItem (j)
    End If
    Next j
    Next i
    End Sub


    It would be great too if some1 cud show me how to sort the list.



  2. #2
    Tom Ogilvy
    Guest

    Re: adding into combo box and removing duplicates

    See John Walkenbach's article. He uses a listbox, but it is the same for a
    combobox.

    http://j-walk.com/ss/excel/tips/tip47.htm

    However, I wouldn't use the change event. Perhaps the dropdown event. Or if
    the data is static, the worksheet activate event.

    --
    Regards,
    Tom Ogilvy


    "Abhay Sanan" <[email protected]> wrote in message
    news:[email protected]...
    > i have a list in my spreadsheet which needs to be added to my combo box
    > list. The problem is that there are repeated number of these values. This

    is
    > the code I have written but it does not work as i need it to. Not all the
    > values have been added into the list. Also for every letter i type in the
    > combo box this function is called making it slow. If some1 could correct

    it,
    > it would be great. Thanks!
    >
    > Private Sub ComboBox1_Change()
    > Dim i As Integer
    > Dim j As Integer
    > Dim count As Integer
    > Dim entry As String
    > Dim check As String
    >
    > Range("C8",Range("C8").End(xlDown)).Select
    > count = Selection.Rows.count
    >
    > Worksheets("Portfolio").Range("DR11")=count
    > For i = 8 To count
    > entry = Cells(i, 3).Value
    > ComboBox1.AddItem (entry)
    > Next i
    >
    > For i = 8 To count
    > entry = Cells(i, 3).Value
    > For j = i + 1 To count
    > check = Cells(j, 3).Value
    > If entry = check Then
    > ComboBox1.RemoveItem (j)
    > End If
    > Next j
    > Next i
    > End Sub
    >
    >
    > It would be great too if some1 cud show me how to sort the list.
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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