Option Explicit
Sub CompareRangeToArrayFindMissingAndDupes()
Dim aInput As Variant
Dim lX As Long
Dim b As Variant
Dim vKey As Variant
Dim sMissing As String
Dim sDupes As String
aInput = Array(1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 16, 20, 21)
ReDim b(1 To UBound(aInput, 1) + 1, 1 To 1)
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For lX = 0 To UBound(aInput, 1) 'Load keys, set item = 0
.Item(aInput(lX)) = 0
Next
Sheets("sheet1").Range("d2").Resize(UBound(b, 1)).Value = Application.Transpose(.keys)
Sheets("sheet1").Range("e2").Resize(UBound(b, 1)).Value = Application.Transpose(.items)
With Sheets("sheet1") 'Load input range to array
aInput = .Range("a2", .Range("a" & Rows.Count).End(xlUp)).Value
End With
For lX = 1 To UBound(aInput, 1) 'Increment dictionary item values
If .exists(aInput(lX, 1)) Then
.Item(aInput(lX, 1)) = .Item(aInput(lX, 1)) + 1
End If
Next
Sheets("sheet1").Range("i2").Resize(UBound(b, 1)).Value = Application.Transpose(.keys)
Sheets("sheet1").Range("j2").Resize(UBound(b, 1)).Value = Application.Transpose(.items)
For Each vKey In .keys
Debug.Print vKey, .Item(vKey), IsMissing(.Item(vKey)), IsEmpty(.Item(vKey))
If .Item(vKey) = 0 Then
sMissing = sMissing & vKey & ", "
End If
If .Item(vKey) > 1 Then
sDupes = sDupes & vKey & ", "
End If
Next
If Len(sMissing) > 2 Then sMissing = Left(sMissing, Len(sMissing) - 2)
If Len(sDupes) > 2 Then sDupes = Left(sDupes, Len(sDupes) - 2)
Range("B49").Value = "Missing:"
Range("B50").Value = sMissing
Range("B52").Value = "Dupes:"
Range("B53").Value = sDupes
End With
End Sub