'建立字典,把對象賦予dictionary,(等於判斷依據)
Set dic = CreateObject("scripting.dictionary")
'從A列最後一列開始進行篩選: step -1
'如果是從第一列開始會有刪除跳行情況,無法達成刪除重複效果 For i = Range("A65536").End(3).Row To 1 Step -1
'如果A欄數據已經存在字典中(等於重複了)則執行THEN
If dic.exists(Cells(i, "A").Value) Then
'刪除該列
Rows(i).Delete
Else
'若A欄數據未存於字典內,則將其加入字典
dic(Cells(i, "A").Value) = ""
End If
Next i
Dim dr As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Sheets("工作表1").Select
Range("A2").Select
Set dic = CreateObject("scripting.dictionary")
For i = Range("A2000").End(3).Row To 1 Step -1
If dic.exists(Cells(i, "A").Value) Then
If dr Is Nothing Then
Set dr = Rows(i)
Else
Set dr = Union(dr, Rows(i))
End If
Else
dic(Cells(i, "A").Value) = ""
End If
Next i
dr.EntireRow.Delete
Set dr = Nothing
Set dic = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True