【发布时间】:2017-07-23 04:16:18
【问题描述】:
需要帮助,我有以下代码:
Dim LRAS, matchFoundIndex, iCntr As Long
LRAS = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For iCntr = 3 To LRAS
If Cells(iCntr, 1) <> "" Then
matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" & LRAS), 0)
If iCntr <> matchFoundIndex Then
Cells(iCntr, 14) = "Duplicate"
'at this point duplicate
End If
End If
Next iCntr
'-----------
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim deleteRow As Long
Dim wrksht As Worksheet
Set wrksht = ActiveSheet
For deleteRow = wrksht.Range("N" & Rows.Count).End(xlUp).Row To 3 Step -1
If wrksht.Range("N" & deleteRow).Value = "Duplicate" Then
Rows(deleteRow).EntireRow.Delete
End If
Next deleteRow
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
此代码基本上搜索重复值,然后说这些值是重复的。下一步是删除第二个重复项。 我想将此构建为一个事件,而不是两个单独的事件。有没有办法做到这一点?或者是否有另一种方法可以根据第一列中的值删除重复的行?
【问题讨论】:
标签: excel delete-row vba