+ Reply to Thread
Results 1 to 3 of 3

How to remove duplicate items from the Combobox

Hybrid View

  1. #1
    Registered User
    Join Date
    05-19-2014
    Posts
    2

    Red face How to remove duplicate items from the Combobox

    Hello!
    I've tied to look for a solution or formula to my problem but none seems to work.
    I have made a userform that searches and displays scores of my students. I have made it to work when it comes to displaying the scores of a particular student. The student's name can be chosen from the combobox. My problem however is that it displays name duplicates. The names of students are taken from a sheet in my excel workbook. There really are duplicates of names in the sheet but they vary according to the month and scores.

    Here is my code below of the userform
    
    Private Sub UserForm_initialize()
    row_review = 2
    
        Dim TheSheet As Worksheet
        Set TheSheet = Sheets("Toeic Test Result")
        
        name1.Clear
    Do
    DoEvents
    row_review = row_review + 1
    item_in_review = TheSheet.Range("A" & row_review + 1)
    If Len(item_in_review) > 0 Then name1.AddItem (item_in_review)
    
    Loop Until item_in_review = ""
    
    'Empty month1
    month1.Clear
    
    'Fill month1
    With month1
        .AddItem "January"
        .AddItem "February"
        .AddItem "March"
        .AddItem "April"
        .AddItem "May"
        .AddItem "June"
        .AddItem "July"
        .AddItem "August"
        .AddItem "September"
        .AddItem "October"
        .AddItem "November"
        .AddItem "December"
    End With
    
    'Empty listening1
    tbl1.value = ""
    
    'Empty reading1
    tbr1.value = ""
    
    'Empty speaking1
    tbo1.value = ""
    
    'Empty writing1
    dbl1.value = ""
    
    End Sub
    Legends:
    combobox name = name1
    sheet name = Toeic Test Result


    Learning VBA is both interesting and challenging. I hope you guys can help me with this.
    Thanks

  2. #2
    Valued Forum Contributor Miroslav R.'s Avatar
    Join Date
    05-16-2013
    Location
    NMnV, Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    479

    Re: How to remove duplicate items from the Combobox

    Hi there,

    For case like this, I use application.match = matching the student name in sudent names column. If match value = row number You are on, then add, else skip.

    Do
    DoEvents
    row_review = row_review + 1
    item_in_review = TheSheet.Range("A" & row_review + 1)
    If Len(item_in_review) > 0 and Application.Match(item_in_review, TheSheet.Columns(1),0) = row_review+1 Then name1.AddItem (item_in_review)
    Loop Until item_in_review = ""
    Not tested, but should work.
    Regards
    Miroslav R.

    (If You like my solutions, feel free to add reputation.)

  3. #3
    Registered User
    Join Date
    05-19-2014
    Posts
    2

    Re: How to remove duplicate items from the Combobox

    Thanks! Ill try this one.

+ 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. Populating Userform ComboBox Using Items from Content Control Combobox
    By anarxo in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2014, 01:00 PM
  2. [SOLVED] ComboBox populated in 2 ways and need to remove duplicate entries
    By jeenius99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2012, 03:23 AM
  3. Pivot tables - remove duplicate items
    By cmb80 in forum Excel General
    Replies: 6
    Last Post: 05-09-2012, 05:34 AM
  4. Remove Combobox Duplicated items
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2009, 02:35 AM
  5. Remove Duplicate Array Items
    By erikcw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2005, 07:30 PM

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