如何识别两列中具有相同值的行?

我试图识别整个行,如果列B 列C有一个VBA脚本的重复值。 例如,如果我有一个表,其中包含:

ID Age Grade 1 14 90 2 15 78 3 14 90 4 16 86 5 16 86 6 15 89 7 14 88 

在运行脚本之后,我想要一个新的工作表,其中列B 列C中具有重复值的行。因此,新工作表将如下所示:

 ID Age Grade 1 14 90 3 14 90 4 16 86 5 16 86 

这是我迄今在识别行方面的。 我不是那么远。

 Sub ID() Dim LastRowcheck As Long, n1 As Long Dim LastRowcheck2 As Long, n2 As Long With Worksheets("grades") LastRowcheck = .Range("B" & .Rows.Count).End(xlUp).Row LastRowcheck = .Range("C" & .Rows.Count).End(xlUp).Row For n1 = LastRowcheck To 1 Step -1 If .Cells(n1, 1).Value = Cells(n1 + 1, 1).Value And .Cells(n2, 1).Value = Cells(n2 + 1, 1).Value Then '''export to new sheet End If Next n1 End With End Sub 

使用application.countifs来标识倍数。

 Dim lastRowcheck As Long, n1 As Long With Worksheets("grades") lastRowcheck = Application.Max(.Range("B" & .Rows.Count).End(xlUp).Row, _ .Range("C" & .Rows.Count).End(xlUp).Row) For n1 = lastRowcheck To 1 Step -1 If Application.CountIfs(.Columns("B"), .Cells(n1, "B").Value2, .Columns("C"), .Cells(n1, "C").Value2) > 1 Then '''export to new sheet Debug.Print .Cells(n1, "A") & ":" & .Cells(n1, "B") & ":" & .Cells(n1, "C") End If Next n1 End With