So sánh trùng và không trùng trên 2 cột.

Liên hệ QC
Bạn thử Sub SoSanh này:

Mã:
Sub SoSanh()
Dim List1 As Range, List2 As Range, List12 As Range
Sheets("Check").Select
Range(Cells(3, 3), Cells(65536, 5)).ClearContents
rc = Cells(3, 1).End(xlDown).Row
Set List1 = Range(Cells(3, 1), Cells(rc, 1))
Set List2 = Range(Cells(3, 2), Cells(rc, 2))
Set List12 = Range(Cells(3, 5), Cells(rc, 5))
r1 = 3
r2 = 3
r12 = 3
For r = 3 To rc
[COLOR=blue]  'So sanh list1 voi list2[/COLOR]
  kiemtra = Application.WorksheetFunction.CountIf(List2, Cells(r, 1))
  If kiemtra = 0 Then 'list1<>list2
    Cells(r1, 3) = Cells(r, 1)
    r1 = r1 + 1
  Else                  [COLOR=blue] 'list1=list2
[/COLOR]    kiemtra = Application.WorksheetFunction.CountIf(List12, Cells(r, 1))
    If kiemtra = 0 Then
      Cells(r12, 5) = Cells(r, 1)
      r12 = r12 + 1
    End If
  End If
 
[COLOR=blue] 'So sanh list1 voi list2[/COLOR]
  kiemtra = Application.WorksheetFunction.CountIf(List1, Cells(r, 2))
  If kiemtra = 0 Then 'list2<>list1
    Cells(r2, 4) = Cells(r, 2)
    r2 = r2 + 1
  Else                  [COLOR=blue] 'list1=list2
[/COLOR]    kiemtra = Application.WorksheetFunction.CountIf(List12, Cells(r, 2))
    If kiemtra = 0 Then
      Cells(r12, 5) = Cells(r, 2)
      r12 = r12 + 1
    End If
  End If
Next
End Sub


Bạn ơi file bạn sai sao ấy. Mình test thử ko đúng. :(
 
Web KT
Back
Top Bottom