我有从 A 到 K 列的数据集,并且想从 A、D、F、J 和 K 列中找到重复的数据行。
我有以下代码:
Sub RemoveDupes2()
Dim r As Long, lr As Long
Application.ScreenUpdating = False
lr = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("L2:L" & lr)
.Formula = "=ROW()"
.Value = .Value
End With
Range("A2:L" & lr).Sort Key1:=Range("A2"), Order1:=1, Key2:=Range("B2"), Order2:=1
With Range("M2:M" & lr)
.FormulaR1C1 = "=RC[-12]&RC[-11]&RC[-6]&RC[-4]&RC[-2]"
.Value = .Value
End With
With Range("N2:N" & lr)
.FormulaR1C1 = "=COUNTIF(R1C13:RC[-1],RC[-1])"
.Value = .Value
End With
For r = lr To 2 Step -1
If Cells(r, 14).Value > 2 Then
Rows(r).Delete
ElseIf Cells(r, 14).Value = 2 Then
Cells(r - 1, 1).Resize(, 7).Font.Bold = True
Rows(r).Delete
End If
Next r
lr = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("A2:L" & lr).Sort Key1:=Range("L2"), Order1:=1
Range("L2:N" & lr).ClearContents
Application.ScreenUpdating = True
End Sub
该代码当前删除了整个数据集,我不确定为什么这样做,因为我是 VBA 的新手。