通过选择最大值删除重复的行

时间:2019-02-25 15:32:48

标签: excel

我有一个包含3列的数据,并且有重复项。我想为A列中的每个重复项从C列中选择最大值。是否有更快的方法?

Sub HighestValues()

'This Sub is to pick the highest value if there are duplicates

Dim LastRow As Long
LastRow = Worksheets("Product Qty").Cells(Rows.Count, "A").End(xlUp).Row
Dim i As Long
Application.ScreenUpdating = False

For i = LastRow To 2 Step -1
    If Cells(i, "A").value = Cells(i - 1, "A").value Then
        If Cells(i - 1, "C").value > Cells(i, "C").value Then
        Rows(i).delete
        Else
        Rows(i - 1).delete
        End If
    End If
Next i

Application.ScreenUpdating = True
End Sub

0 个答案:

没有答案