+ Reply to Thread
Results 1 to 15 of 15

count unique records in one column based on criteria in a different column

Hybrid View

  1. #1
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,085

    Re: count unique records in one column based on criteria in a different column

    If the macro is a must try

    Option Explicit
    
    Sub CollectData()
    Dim WkRg As Range
    Dim WkTb()
    Dim ObjDic1   As Object
    Dim ObjDic2   As Object
    Dim I  As Long
    Dim Temp
    Dim F
    
        Set ObjDic1 = CreateObject("Scripting.Dictionary")
        Set ObjDic2 = CreateObject("Scripting.Dictionary")
        Set WkRg = Sheets("Cases_Out").Cells(1, 1).CurrentRegion
        WkTb = WkRg
        With ObjDic1
            For I = 2 To UBound(WkTb, 1)
                Temp = WkTb(I, 1) & "/" & WkTb(I, 2)
                If (.exists(Temp)) Then
                    .Item(Temp) = .Item(Temp) + 1
                Else
                    .Item(Temp) = 1
                End If
            Next I
            For Each F In .keys
                If (.Item(F) = 1) Then
                    Temp = Split(F, "/")
                    With ObjDic2
                        If (.exists(Temp(0))) Then
                            .Item(Temp(0)) = .Item(Temp(0)) + 1
                        Else
                            .Item(Temp(0)) = 1
                        End If
                    End With
                End If
            Next
        End With
        With ObjDic2
            Sheets("Result").Cells.ClearContents
            Sheets("Result").Range("A1").Resize(1, 2) = Array("Name", "Count")
            Sheets("Result").Range("A2").Resize(.Count, 1) = Application.Transpose(.keys)
            Sheets("Result").Range("B2").Resize(.Count, 1) = Application.Transpose(.items)
        End With
    End Sub
    Attached Files Attached Files
    Last edited by PCI; 11-18-2014 at 04:29 PM.
    - Battle without fear gives no glory - Just try

+ 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] Count unique entries based off unique criteria in another column
    By hambly in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 06-11-2014, 03:33 PM
  2. Count unique occurrances based off criteria in a different column
    By Enovy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-05-2013, 03:28 PM
  3. Count unique records in a column
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 11:51 AM
  4. [SOLVED] Count Unique Values in Column A that meet criteria in Column B
    By ashakespeare in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-04-2012, 07:33 PM
  5. Replies: 5
    Last Post: 09-18-2011, 10:44 PM

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