私はスプレッドシートを通過し、2つの列(列QとD)で別々に提供される2つの基準に基づいて重複するエントリ(行)を削除するマクロを作成しています。最後のエントリを保持する、重複を削除する -
これは私が持っているものです。小さなデータセットでテストしましたが、が遅いです。
Sub RemoveDupesKeepLast()
dim i As Integer
dim criteria1, criteria2 As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
'start at bottom of sheet, go up
For i = ActiveSheet.UsedRange.Rows.Count to 2 Step -1
'if there is no entry, go to next row
If Cells(i, "Q").Value = "" Then
GoTo gogo:
End If
'set criteria that we will filter for
criteria1 = Cells(i, "D").Value
criteria2 = Cells(i, "Q").Value
'filter for criteria2, then criteria1 to get duplicates
ActiveSheet.Range("A":"CI").AutoFilter field:=17, Criteria1:=criteria2, Operator:=xlFilterValues
ActiveSheet.Range("A":"CI").AutoFilter field:=4, Criteria1:=criteria1, Operator:=xlFilterValues
'if there are duplicates, keep deleting rows until only bottom-most entry is left behind
Do While Range("Q2", Cells(Rows.Count, "Q").End(xlUp)).Cells.SpecialCells(xlCellTypeVisible).Count > 1
ActiveSheet.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1,17).EntireRow.Delete
Loop
'reset autofilter
If ActiveSheet.FilterMode Then
Cells.AutoFilter
End If
gogo:
Next i
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
私はこの問題に近づき、状況を速めることができますか?今のように、私は基本的に各行をチェックしてから上に行きます。シートは、実際には30,000行から最大限までです。私がやろうとしていることをより速く、よりクリーンな方法で達成すべきだと思うが、私は考えることができない。
あなたは今何をしたいですか? Q&D値を縮め、A列からC列までの重複を検索しますか? –
重複を定義するルールは何ですか? –
@ Karthick私は値を連結していません。私のシートのすべての行について、重複のためにシート全体をフィルタリングするために、Q列とD列の値を調べています。重複は、同じQ値とD値を持ちます。したがって、QとDをフィルタリングすると、複数の行が存在する場合、重複が存在します。それから、一番上の行を削除して一番下の行を残します。私は、重複を取り除き、最後のエントリを保持するためだけに探しています - それ以外は何もありません。 – YOO629