+ Reply to Thread
Results 1 to 10 of 10

Avoid duplicates in a listbox populated using search keyword

  1. #1
    Registered User
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    19

    Avoid duplicates in a listbox populated using search keyword

    Hi,

    I have a listbox which is populated using keyword search. I want to avoid duplicates in the search result.
    Listbox name : Members
    Following is the code i use :

    Please Login or Register  to view this content.
    The code in red color is a result of lot of tweaking.
    This is where I was failed to remove duplicates. It worked partially though.

    Kindly help me out on removing duplicates from the listbox

    Best Regards
    Sivakumar

    Note :- This question was raised in another forum. But it was not answered. I have made changes in this forum to make it more readable. PFB the link to that forum.
    http://www.mrexcel.com/forum/excel-q...h-keyword.html
    Last edited by sivakumar123; 01-10-2013 at 07:51 AM. Reason: To Solve

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Avoid duplicates in a listbox populated using search keyword

    Hi Sivakumar,

    I have re-written your code and moved the code to a different event (_exit) to make sure the routine will only get started once the entire search argument has been filled in as opposed for every character added. You are free to move the routine back to the original event if you want to.

    Please Login or Register  to view this content.
    Hope this helps you out a bit
    If you like my contribution click the star icon!

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Avoid duplicates in a listbox populated using search keyword

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Avoid duplicates in a listbox populated using search keyword

    Thank You All...
    I found OllieB's suggestion more suitable for program...
    Here is the final code :

    Please Login or Register  to view this content.
    Best Regards
    Sivakumar

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Avoid duplicates in a listbox populated using search keyword

    Dear Sivakumar,

    thank you for the feedback. Can you please explain why you have added the below code inside the search loop?

    Please Login or Register  to view this content.
    If you want to incorporate this check, I suggest you do it at the beginning of the routine. Note that Members is already cleared at the beginning of the routine and does not need to be cleared inside this loop.

  6. #6
    Registered User
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Avoid duplicates in a listbox populated using search keyword

    OllieB,

    That's because i have another range which is being populated. I removed that here to cut short the length of the code. Also, it does not have any duplication issues.
    This is the removed piece of code...

    Please Login or Register  to view this content.

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Avoid duplicates in a listbox populated using search keyword

    Dear Sivakumar,

    I still do not understand why you added that bit of code.The value of SearchBox will not change WHILE you are inside the loop of populating the ListBox. But anyway, I will leave that decision up to you.

    Please remember to click on the star icon if you are happy with my contribution to your questions.

  8. #8
    Registered User
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Avoid duplicates in a listbox populated using search keyword

    OllieB,

    If that bit of code is not present, once I use backspace and clears the search box, it will be populated with all the Team Names.
    I wanted the list box to be blank, when nothing is present in the search box at any point of time.

    Best Regards
    Sivakumar

  9. #9
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Avoid duplicates in a listbox populated using search keyword

    Svikumar,

    I understand that, but it is sufficient to place the code below at the beginning of the routine itself (immediately following ContactForm.Members.Clear statement), so

    Please Login or Register  to view this content.
    If you do that, your code will also bypass the first search of the range using an empty search argument and so forth. Much cleaner and quicker.

  10. #10
    Registered User
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Avoid duplicates in a listbox populated using search keyword

    OllieB,

    Well, Thanks for that too...
    I've made that change. I had not really given it a thought before.

    Best Regards
    Sivakumar

+ 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