Sub ABC()
Dim sArr(), Res(), sRow&, i&, n&, k&, ikey
i = Range("C8").End(xlDown).Row
n = Range("D8").End(xlDown).Row
If i < n Then i = n
sArr = Range("C8:D" & i).Value
sRow = UBound(sArr)
ReDim Res(1 To sRow, 1 To 1)
With CreateObject("scripting.dictionary")
For i = 1 To sRow
ikey = sArr(i, 1)
If ikey <> Empty Then .Item(ikey) = .Item(ikey) + 1
Next i
For i = 1 To sRow
ikey = sArr(i, 2)
n = .Item(ikey)
If n > 0 Then
k = k + 1
Res(k, 1) = ikey
.Item(ikey) = .Item(ikey) - 1
End If
Next i
End With
If k Then Range("F8").Resize(k) = Res
End Sub