+ Reply to Thread
Results 1 to 2 of 2

Thread: filter unique records with its corresponding column

  1. #1
    Registered User
    Join Date
    05-10-2010
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    1

    filter unique records with its corresponding column

    Hi, everyone, i am new here.
    Hope someone can solve my problem

    here is the thing:

    Column A B
    Pig 20
    Pig 3
    Cow 10
    Cow 3

    what i wanted

    Column A B
    Pig 20
    Cow 10

    I tried unique filtering but it wont put in the column B if i am to unique filter the column A

    Any help appreciated

  2. #2
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,150

    Re: filter unique records with its corresponding column

    Hi jungelbobo
    something like

    Sub ptest()
        Dim a, b(), i!, n!
        With Range("a1", Range("a" & Rows.Count).End(xlUp)).Resize(, 2)
            a = .Value
         End With
        ReDim b(1 To UBound(a, 1), 1 To 2)
        With CreateObject("Scripting.Dictionary")
            .CompareMode = vbTextCompare
            For i = 1 To UBound(a, 1)
                If Not IsEmpty(a(i, 1)) Then
                    If Not .exists(a(i, 1)) Then
                        n = n + 1
                        b(n, 1) = a(i, 1)
                        .Add a(i, 1), n
                    End If
                    b(.Item(a(i, 1)), 2) = b(.Item(a(i, 1)), 2) + a(i, 2)
                End If
            Next
      End With
        Range("D1").Resize(n, 2).Value = b
    End Sub
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0