+ Reply to Thread
Results 1 to 10 of 10

Remove duplicate values from Listbox

  1. #1
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Remove duplicate values from Listbox

    Hi All,

    Column A has values increasing by 1 but not necessarily each row, i.e.

    1
    1
    1
    2
    2
    2
    3
    3
    3
    4
    4
    4
    4
    5
    5
    5
    5
    6
    7
    7
    7
    8
    8
    9
    10
    10
    11
    11
    11
    11
    12
    13
    13
    14
    14
    14

    I have a listbox which I want to Initialize by listing these values but not duplicating them (so in this case it would contain 1-14). Here is the mindblowingly complicated code I currently have:

    Please Login or Register  to view this content.
    This gives me the list as it appears on the sheet but doesn't get rid of the duplicates for me. Any help would be greatly appreciated. Many Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Remove duplicate values from Listbox

    Quickest way is off a pivot table
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Remove duplicate values from Listbox

    1 way using advanced filter to create a unique list in column B and use this range in your code. Something like this...

    Please Login or Register  to view this content.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Remove duplicate values from Listbox

    Try:-
    Please Login or Register  to view this content.
    Last edited by MickG; 05-14-2014 at 09:55 AM.

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Remove duplicate values from Listbox

    or
    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Remove duplicate values from Listbox

    No loop
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove duplicate values from Listbox

    Here's another..

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Remove duplicate values from Listbox

    Thanks All,

    All work fine, I went with apo's one as I found easiest to comprehend (as an amateur VBA user!)

    Is it possible to modify this so that the range isn't just column A but all the cells in column A that have an empty cell in the same row in a different column? I've attached a workbook example that I've thrown together. In the example column L has a "1" along from all the items I don't want to appear in the box so I would be expecting the output 10-14 in the listbox.

    I've tried modifying the code in here in different ways to define the range but I'm getting the 1004 error so I'm clearly missing the point!

    Let me know if I should be starting a new thread for this. Thanks
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Remove duplicate values from Listbox

    Wrap the line that adds the item into the Dictionary in an If Then /End If Statement..

    Like:

    Please Login or Register  to view this content.
    Another way you could do it if you had heaps of rows would be to autofilter by Column L for anything <> 1 and then change the For Each line so it only looks at visible Cells after the autofilter..

    Having said that.. of course Jindons will be most efficient as it doesn't even use a loop..

    Fotis1991's approach doesn't use a loop either so i would imagine that would be fast too.

    But probably the simple If Then/End If will do for small amounts of rows..
    Last edited by apo; 05-14-2014 at 08:13 PM.

  10. #10
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Remove duplicate values from Listbox

    That works great thanks, the main sheet I'm working on has ~ 2300 rows of which this should be picking up between 10 and 15 at a time and it seems to be going OK. Hopefully it continues this way, many thanks for your help!

+ 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. [SOLVED] Trying to Remove Duplicate Values of Last Name List
    By sonicexcel in forum Excel General
    Replies: 3
    Last Post: 04-24-2014, 11:01 PM
  2. [SOLVED] ListBox of Unique values to also display Duplicate(Count)
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-26-2013, 04:49 PM
  3. remove duplicate values from array
    By nikko50 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2013, 07:14 PM
  4. Code not to add duplicate values to my 2 column-listbox
    By Cijo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 05:36 PM
  5. Excel 2007 : Remove Duplicate Values from top 5
    By loknath in forum Excel General
    Replies: 1
    Last Post: 11-08-2011, 09:46 AM

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