我如何找到同一列中每个重复项的最后一行索引?

问题描述 投票:2回答:1

我正在尝试创建一个程序,以便它可以找到位于同一列内的每个重复项的最后一行索引,并存储它们的值。例如,在图片中,名称为John,trump,alice和sarah的最后一行索引应分别给我13,17,23,26。当前,我的代码只能识别重复项,因此我不仅要为我显示的图片而且要在所有情况下如何查找每个重复项的最后一行索引?

enter image description here

Sub Testing()

    Dim mycell As Range, RANG As Range

    With Sheets(1)

        ' Build a range (RANG) between cell F2 and the last cell in column F
        Set RANG = Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))

    End With

    ' For each cell (mycell) in this range (RANG)
    For Each mycell In RANG

        ' If the count of mycell in RANG is greater than 1, then set the value of the cell 1 across to the right of mycell (i.e. column G) as "Duplicate Found"
        If Application.WorksheetFunction.CountIf(RANG, mycell.Value) > 1 Then

        'how do i find the last row index of each duplicate here?

    Next mycell

End Sub
excel vba
1个回答
推荐问答