Function Compare2List(ByVal SourceArray, ByVal Array2Compare, ByVal ColIndex As Long, ByVal CompareType As Boolean)
Dim lR As Long, lC As Long, n As Long
Dim lFirstRow As Long, lEndRow As Long, lFirstCol As Long, lEndCol As Long
Dim aSource, aDest, aComp, Item
Dim sTmp As String, str As String
Dim dic As Object
'Nap Dictionary
Set dic = CreateObject("Scripting.Dictionary")
aComp = Array2Compare
For Each Item In aComp
str = CStr(Item)
If Len(str) Then
If Not dic.Exists(str) Then dic.Add str, ""
End If
Next
aSource = SourceArray
lFirstRow = LBound(aSource, 1)
lEndRow = UBound(aSource, 1)
lFirstCol = LBound(aSource, 2)
lEndCol = UBound(aSource, 2)
n = lFirstRow - 1
ReDim aDest(lFirstCol To lEndCol, lFirstRow To lFirstRow)
For lR = lFirstRow To lEndRow
sTmp = CStr(aSource(lR, ColIndex))
If Len(sTmp) Then
If dic.Exists(sTmp) = CompareType Then
n = n + 1
ReDim Preserve aDest(lFirstCol To lEndCol, lFirstRow To n)
For lC = lFirstCol To lEndCol
aDest(lC, n) = aSource(lR, lC)
Next
End If
End If
Next
If n >= lFirstRow Then Compare2List = Transpose2DArray(aDest)
End Function
Function Transpose2DArray(ByVal arr2D)
Dim arr(), aTemp
Dim lR As Long, lC As Long
On Error Resume Next
aTemp = arr2D
ReDim arr(LBound(aTemp, 2) To UBound(aTemp, 2), LBound(aTemp, 1) To UBound(aTemp, 1))
For lR = LBound(aTemp, 1) To UBound(aTemp, 1)
For lC = LBound(aTemp, 2) To UBound(aTemp, 2)
arr(lC, lR) = aTemp(lR, lC)
Next
Next
Transpose2DArray = arr
End Function