Removes duplicates from dropdown list combobox

  • hello can someone help me with the code how to remove duplicates from dropdown list combobox? i need the additional code for preventing the duplicates from the dropdown list. because this code lists the whole data without removing the duplicates. i attach the example file below


    Private Sub ComboBox1_Change()
    Dim i As Long
    With Me.ComboBox1
    If Not IsArrow Then .List = Range("AccountsList").Value
    If .ListIndex = -1 And Len(.Text) Then
    For i = .ListCount - 1 To 0 Step -1
    If InStr(1, .List(i), .Text, 1) = 0 Then .RemoveItem i
    Next i
    .DropDown
    End If
    End With
    End Sub


    Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    IsArrow = KeyCode = vbKeyUp Or KeyCode = vbKeyDown
    If KeyCode = vbKeyReturn Then Me.ComboBox1.List = Range("AccountsList").Value
    End Sub

  • Would you not be better to collect the data prior to populating the combo box then parse this to create a new list which can then be passed into the combo box list?


    Something like the following:


  • have u tried the code u write on the excel file attached? i have tried ur code but unfortunately it didnt work. Please help :(
    could u write the code in excel file if u dont mind

  • Afraid I can't, can't download the files in the work PC, firewalls will just eat it right up.


    Specifically what wasn't working? Error? Can you debug and step through and confirm what line the error occurs on?

  • [ATTACH=JSON]{"data-align":"none","data-size":"full","title":"vvv.jpg","data-attachmentid":1205981}[/ATTACH]i literally removed all my old code and replace with yours and i already changed the "combobox1" and the range tho. no error nor debug. it just didnt show any changes, no drop down list no debug no error

  • hello,
    use

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!