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

时间:2017-04-19 16:14:33

标签: excel vba parsing

如果列B AND 列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列 AND 列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

1 个答案:

答案 0 :(得分:2)

使用Function AppendIndex() Dim fld As DAO.Field Set fld = DBEngine(0)(0).TableDefs("Submission_Key").CreateField("Index",dbLong) fld.Attributes = dbAutoIncrField DBEngine(0)(0).TableDefs("Submission_Key").Fields.Append fld Set fld = Nothing End Function 识别倍数。

application.countifs