下面显示的代码来自此示例:excel: check for duplicate rows based on 3 columns and keep one row
Sub Testing()
Dim lastrow As Long
With ThisWorkbook.Worksheets(1)
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
.Range("A1:M" & lastrow).RemoveDuplicates Columns:=Array(1, 4, 5, 6, 7, 11), _
Header:=xlYes
End With
End Sub
有重复项时,代码工作正常。但是,如果没有,则返回错误。因此,我想知道是否有一种方法可以快速计算重复项的数量,也许要加上条件或类似的东西。