Sub CountUnique()
Application.ScreenUpdating = False
Dim LastRow As Long, srcWS As Worksheet, desWS As Worksheet, arr As Variant, dic As Object, dic2 As Object
Dim Val As String, key As Variant, rng As Range, x As Long, y As Long, fVisRow As Long, lVisRow As Long
Set srcWS = Sheets("raw data")
Set desWS = Sheets("summary")
With srcWS
LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
arr = .Range("A2", .Range("A" & .Rows.Count).End(xlUp)).Value
End With
Set dic = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(arr, 1)
Val = arr(i, 1)
If Not dic.Exists(Val) Then
dic.Add Val, Nothing
End If
Next i
For Each key In dic
With srcWS
.Cells(1, 1).CurrentRegion.AutoFilter 1, key
fVisRow = Rows("2:" & LastRow).SpecialCells(xlCellTypeVisible).Row
lVisRow = Cells(Rows.Count, "A").End(xlUp).Row
For Each rng In .Range("B2:B" & LastRow).SpecialCells(xlCellTypeVisible)
If WorksheetFunction.CountIf(.Range("B" & fVisRow & ":B" & lVisRow), rng) > 1 Then
If Not dic2.Exists(rng.Value) Then
dic2.Add rng.Value, Nothing
x = x + 1
Else
x = x + 1
End If
ElseIf WorksheetFunction.CountIf(.Range("B" & fVisRow & ":B" & lVisRow), rng) = 1 Then
y = y + 1
End If
Next rng
End With
With desWS
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 3) = Array(key, x, y)
End With
x = 0
y = 0
dic2.RemoveAll
Next key
Application.ScreenUpdating = True
End Sub