Count Col.C in Sheet2, not Sheet1...
Sub test()
Dim a, b, i As Long, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
dic.CompareMode = 1
With Sheets("sheet2")
With .Range("c2", .Range("c" & Rows.Count).End(xlUp))
a = .Value
b = .Columns(10).Value
End With
End With
For i = 1 To UBound(a, 1)
If Not dic.exists(a(i, 1)) Then
dic(a(i, 1)) = Array(b(i, 1), 1)
Else
dic(a(i, 1)) = Array(dic(a(i, 1))(0), dic(a(i, 1))(1) + 1)
End If
Next
With Sheets("sheet1")
With .Range("c2", .Range("c" & Rows.Count).End(xlUp))
a = .Value
ReDim b(1 To UBound(a, 1), 1 To 1)
For i = 1 To UBound(a, 1)
If dic.exists(a(i, 1)) Then
b(i, 1) = dic(a(i, 1))(0)
a(i, 1) = dic(a(i, 1))(1)
Else
a(i, 1) = Empty
End If
Next
.Columns(21).Value = b
.Columns(22).Value = a
End With
End With
End Sub
Bookmarks