Function đếm trùng lặp cho 2 array:
Public Function DemTrungLap(Arr1 As Variant, Arr2 As Variant) As Long
Dim varElement As Variant
On Error Resume Next
For Each varElement In Arr1
'lMatch = 0
'lMatch = Application.Match(varElement, arr2, 0)
If Not IsError(Application.Match(varElement, Arr2, 0)) Then
DemTrungLap = DemTrungLap + 1
End If
Next varElement
On Error GoTo 0
End Function
Function đếm trùng lặp cho 2 range:
Public Function DemTrungLap(Arr1 As range, Arr2 As range) As Long
Dim varElement As range
On Error Resume Next
For Each varElement In Arr1
If Not IsError(Application.Match(varElement, Arr2, 0)) Then
DemTrungLap = DemTrungLap + 1
End If
Next varElement
On Error GoTo 0
End Function
Chú ý: Trong nhiều tường hợp để đếm trùng lặp chính xác thì cần phải chọn một chuỗi có giá trị duy nhất đi đếm với chuổi có nhiều giá trị trùng lặp trong chính chuỗi đó.
Đăng nhận xét