Consulting

Results 1 to 12 of 12

Thread: Solved: Extract distinct list from a range

  1. #1

    Solved: Extract distinct list from a range

    Hi
    I have values within the range A110 and there are repeated values
    I want to extract a list of unique values in the column E

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Have you tried Advanced Filter, Data>Filter>Advanced Filter?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Yes, I tried Advanced Filter and it doesn't work
    The range is
    A1:D10
    as it doesn't appear in the first post

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]
    Sub Unique()
    Dim r As Range
    Dim d, a
    Set r = Range("A110")
    On Error Resume Next
    Set d = CreateObject("Scripting.Dictionary")
    For Each cel In r
    d.Add CStr(cel), cel
    Next
    a = d.items
    Range("E1").Resize(d.Count) = Application.Transpose(a)
    End Sub

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Thanks for help Mr. mdmackillop
    But it doesn't work .I don't know why?
    Generally here's an attachment with your code ..

  6. #6
    Thanks for help Mr. mdmackillop
    But it doesn't work .I don't know why?
    Generally here's an attachment with your code ..

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Slight change
    [VBA]
    d.Add CStr(cel), CStr(cel)
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Perfect ! Excellent
    Thanks for your help
    Slight change great result
    Another slight request my dear
    The result contains blank cell .. Could I get rid of that??
    Another and last request .. In the column F I want to insert the function that count the times of each value
    =Countif(A1:D10;E1)
    via code

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub Unique()
    Dim r As Range
    Dim d, a
    Set r = Range("A110")
    On Error Resume Next
    Set d = CreateObject("Scripting.Dictionary")
    For Each cel In r
    If cel <> 0 Then d.Add CStr(cel), CStr(cel)
    Next
    a = d.items
    Range("E1").Resize(d.Count) = Application.Transpose(a)
    Range("F1").Resize(d.Count).FormulaR1C1 = "=COUNTIF(R1C1:R10C4,RC[-1])"
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Great .. Perfect.. Excellent
    Thanks a lot for your help
    That's a great forum that has great people

  11. #11
    Knowledge Base Approver VBAX Expert brettdj's Avatar
    Joined
    May 2004
    Location
    Melbourne
    Posts
    649
    Location
    This is solved but for future reference, the Duplicate Master addin - , http://www.experts-exchange.com/A_2123.html - uses the same approach that Malcolm applied (with the Scripting Dictionary)

    It offers the flexibility to manipulate strings when looking for uniques/duplicates (case sensitivity, white space handling, string transformations)

    Cheers

    Dave

  12. #12
    Great addin Mr. Dave
    I like it very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •