Skip to content

Instantly share code, notes, and snippets.

@TGDUY
Created April 26, 2018 01:24
Show Gist options
  • Select an option

  • Save TGDUY/5079325ad7440574ef07da1796d89034 to your computer and use it in GitHub Desktop.

Select an option

Save TGDUY/5079325ad7440574ef07da1796d89034 to your computer and use it in GitHub Desktop.
Function SoSanh(ListA As Range, ListB As Range, Cr As Byte) As Variant
Dim Dic As Object, TmpA As Variant, TmpB As Variant, I As Long, J As Long, Tmp As Variant
Set Dic = CreateObject("Scripting.Dictionary")
TmpA = ListA.Value2: TmpB = ListB.Value2: ReDim Tmp(0)
J = -1
For I = LBound(TmpA, 1) To UBound(TmpA, 1)
If Not Dic.exists(CStr(TmpA(I, 1))) Then Dic.Add CStr(TmpA(I, 1)), CStr(TmpA(I, 1))
Next
For I = LBound(TmpB, 1) To UBound(TmpB, 1)
If Dic.exists(CStr(TmpB(I, 1))) Then
Dic.Remove CStr(TmpB(I, 1))
J = J + 1
ReDim Preserve Tmp(J)
Tmp(J) = CStr(TmpB(I, 1))
End If
Next
If Cr = 1 Then
SoSanh = Application.WorksheetFunction.Transpose(Dic.keys)
ElseIf Cr = 2 Then
SoSanh = Application.WorksheetFunction.Transpose(Tmp)
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment