+ Reply to Thread
Results 1 to 12 of 12

Removing Duplicates from listboz

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Removing Duplicates from listboz

    Hi All

    I have a userform with a couple of listboxes. ONe of the listboxes rowsource is linked to a dynamic range. This range contains duplicates. For example the range currently has 10 apples in it and 5 bananas but in the listbox I only want to see apple and banana once.

    Any ideas how this can be achieved

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Removing Duplicates from listboz

    Instead of using the rowsource property, try placing this in the initialize event for the userform. Just change RowSourceDynamicRange to the dynamic range of items you'd like to use. If you would like to tell me what the range is I could edit for you.
    Please Login or Register  to view this content.
    e/ I forgot to mention you might have to change the name of the listbox if its not ListBox1
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Removing Duplicates from listboz

    Hi

    Thanks for your reply. THe dynamic range depends on an entry in another listbox so this is the code I have tried to adopt into your. However it is not working. Any idea where I am going wrong

    Please Login or Register  to view this content.
    cheers for help
    Last edited by chrisjames25; 10-28-2013 at 09:26 AM.

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Removing Duplicates from listboz

    So the sheet is selected by the listbox named categorylst, and the range on the sheet selected (by the listed box) will D6:Dx?

  5. #5
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Removing Duplicates from listboz

    yep that is correct.

  6. #6
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Removing Duplicates from listboz

    ok It now seems to be removing the duplicates however as I flick through the selections in categorylst it keeps adding to the rowsource for genuslst. What tweak wud I need to make to reset the genus data each time the category lst is changed?

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Removing Duplicates from listboz

    This is untested without a sample worksheet but you cant try:
    Please Login or Register  to view this content.
    This should still be in the userform's initialize event.

  8. #8
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Removing Duplicates from listboz

    Hi

    Unfortuantely it appears to work once or twice when I change the categorylst value but then it crashes and gives the following message:

    Run time error -214717848 (800 10 108):
    Automation error
    The object invoked has disconnected from its clients

    Any thoughts on this would be massively appreciated

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Removing Duplicates from listboz

    Can you redact any sensitive information from your workbook and post it as an example?

    I won't be able to recreate that error.

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Removing Duplicates from listboz

    I'd do it like this, using AddItem is slow and reading/writing to the worksheet should be done in bulk:
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Removing Duplicates from listboz

    Quote Originally Posted by Kyle123 View Post
    I'd do it like this, using AddItem is slow and reading/writing to the worksheet should be done in bulk:
    Please Login or Register  to view this content.
    Hi Sorry for being Stupid but am I supposed to adjust the "Scripting.Dictionary" to something. Also where should I put this code. I put it in the Sub Categorylst_change() but it had no effect.

    THoughts much appreicated

  12. #12
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Removing Duplicates from listboz

    Ok I am understanding your code a bit more but struggling to get it to work. ANy chance you could explain it line by line then I can see if there is a simple reason why when I have put it in it has not worked.

    Cheers

+ 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. Replies: 6
    Last Post: 03-29-2012, 12:16 AM
  2. Removing Duplicates
    By drob59233 in forum Excel General
    Replies: 1
    Last Post: 10-25-2011, 06:44 PM
  3. Get:Removing Duplicates
    By Gary's Student in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 04:05 AM
  4. Removing Duplicates
    By sat in forum Excel General
    Replies: 5
    Last Post: 06-18-2005, 07:05 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