很简单。添加一个名为“重复项”的工作表,然后选择要检查重复项的工作表,然后确保工作表首先按列 A 排序,然后按列 B,然后运行此宏:
Sub GetDuplicates()
On Error GoTo errGetDuplicates
d = 1
x = 1
Do Until Cells(x, 1) = "" 'Looks at each row until it reaches the end
If Cells(x, 1) = Cells(x + 1, 1) Then 'Checks Col 1 for duplicates
If Cells(x, 2) = Cells(x + 1, 2) Then 'Checks Col 2 for duplicates
Sheets("Duplicates").Cells(d, 1) = Cells(x, 1)
Sheets("Duplicates").Cells(d, 2) = Cells(x, 2)
Sheets("Duplicates").Cells(d, 3) = Cells(x, 3)
d = d + 1
x = x + 1
Sheets("Duplicates").Cells(d, 1) = Cells(x, 1)
Sheets("Duplicates").Cells(d, 2) = Cells(x, 2)
Sheets("Duplicates").Cells(d, 3) = Cells(x, 3)
d = d + 1
End If
End If
doneWithError:
x = x + 1
Loop
Exit Sub
errGetDuplicates:
If Err = 1004 Then
array1 = Split(Cells(x, 1), " ")
array2 = Split(Cells(x + 1, 1), " ")
For a = 0 To UBound(array1)
If Not array1(a) = array2(a) Then GoTo unmatched
Next a
array3 = Split(Cells(x, 2), " ")
array4 = Split(Cells(x + 1, 2), " ")
For a = 0 To UBound(array1)
If Not array3(a) = array4(a) Then GoTo unmatched
Next a
Sheets("Duplicates").Cells(d, 1) = Join(array1, " ")
Sheets("Duplicates").Cells(d, 2) = Join(array3, " ")
Sheets("Duplicates").Cells(d, 3) = Cells(x, 3)
d = d + 1
x = x + 1
Sheets("Duplicates").Cells(d, 1) = Join(array2, " ")
Sheets("Duplicates").Cells(d, 2) = Join(array4, " ")
Sheets("Duplicates").Cells(d, 3) = Cells(x, 3)
d = d + 1
GoTo doneWithError
End If
End Sub