Option Explicit
Sub example()
Dim DIC_Big As Object ' Dictionary
Dim DIC_Small As Object ' Dictionary
Dim wks As Worksheet
Dim rngData As Range
Dim aryDataBig As Variant
Dim aryDataSmall As Variant
Dim aryOutput As Variant
Dim n As Long
Set wks = ThisWorkbook.Worksheets("Email List") '<---Change to suit.
With wks
'// Change what column we are looking (for the bigger list) in to suit. //
Set rngData = RangeFound(.Range(.Cells(2, 1), .Cells(.Rows.Count, 1)))
'// Bail if no data. //
If rngData Is Nothing Then Exit Sub
'// Plunk the values from the bigger range into an array. //
aryDataBig = .Range(.Cells(2, 1), rngData).Value
'// Should not be "needed" but for clarity //
Set rngData = Nothing
'// Change what column we are looking (for the smaller list) in to suit. //
Set rngData = RangeFound(.Range(.Cells(2, 2), .Cells(.Rows.Count, 2)))
If rngData Is Nothing Then Exit Sub
aryDataSmall = .Range(.Cells(2, 2), rngData).Value
'// Create and set references to two dictionaries. //
Set DIC_Big = CreateObject("Scripting.Dictionary")
Set DIC_Small = CreateObject("Scripting.Dictionary")
'// Just loop in the keys to build a list of ubique vals. //
For n = 1 To UBound(aryDataBig, 1)
DIC_Big.Item(aryDataBig(n, 1)) = Empty
Next
For n = 1 To UBound(aryDataSmall, 1)
DIC_Small.Item(aryDataSmall(n, 1)) = Empty
Next
'// To use late-bound, plunk the keys from the small DIC into an array (we are //
'// just re-using aryDataSmall, which will now be 1-D in nature. //
aryDataSmall = DIC_Small.Keys
For n = LBound(aryDataSmall, 1) To UBound(aryDataSmall, 1)
'// In essence, loop thru keys in small dictionary, testing ea to see if it //
'// exists in big dictionary. If not, remove from small dictionary //
If Not DIC_Big.Exists(aryDataSmall(n)) Then DIC_Small.Remove (aryDataSmall(n))
Next
'// Again, reuse array, plunking in remaining keys. //
aryDataSmall = DIC_Small.Keys
'// You can probably use Application.TRanspose for this bit. I'm currently in //
'// Excel 2000, and there's something like a 512 cell limit. Anyways, I just //
'// prefer "manually" transposing. //
ReDim aryOutput(LBound(aryDataSmall, 1) To UBound(aryDataSmall, 1), 1 To 1)
For n = LBound(aryDataSmall, 1) To UBound(aryDataSmall, 1)
aryOutput(n, 1) = aryDataSmall(n)
Next
.Range("D2").Resize(UBound(aryOutput, 1) - LBound(aryOutput, 1) + 1).Value = aryOutput
End With
End Sub
Function RangeFound(SearchRange As Range, _
Optional ByVal FindWhat As String = "*", _
Optional StartingAfter As Range, _
Optional LookAtTextOrFormula As XlFindLookIn = xlValues, _
Optional LookAtWholeOrPart As XlLookAt = xlPart, _
Optional SearchRowCol As XlSearchOrder = xlByRows, _
Optional SearchUpDn As XlSearchDirection = xlPrevious, _
Optional bMatchCase As Boolean = False) As Range
If StartingAfter Is Nothing Then
Set StartingAfter = SearchRange(1)
End If
Set RangeFound = SearchRange.Find(What:=FindWhat, _
After:=StartingAfter, _
LookIn:=LookAtTextOrFormula, _
LookAt:=LookAtWholeOrPart, _
SearchOrder:=SearchRowCol, _
SearchDirection:=SearchUpDn, _
MatchCase:=bMatchCase)
End Function