excel: check for duplicate rows based on 3 columns and keep one row

后端 未结 1 1238
闹比i
闹比i 2020-12-21 15:06

This might be a bit much to ask but I\'m wondering if the following is possible. this is all based on my initial question on How do I copy a range of formula values and past

相关标签:
1条回答
  • 2020-12-21 15:48

    This code works for me (lastrow based on this asnwer by @SiddharthRout):

    Sub test()
    
        Dim lastrow As Long
    
        With ThisWorkbook.Worksheets("Sheet1")
            If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
                lastrow = .Cells.Find(What:="*", _
                              After:=.Range("A1"), _
                              Lookat:=xlPart, _
                              LookIn:=xlFormulas, _
                              SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious, _
                              MatchCase:=False).Row
            Else
                lastrow = 1
            End If
    
            'Array(1, 2, 16) means 1 - for A, 2 for B and 16 for P columns
            .Range("A1:P" & lastrow).RemoveDuplicates Columns:=Array(1, 2, 16), _
                Header:=xlYes
        End With
    End Sub
    
    0 讨论(0)
提交回复
热议问题