vba去除重復項,可以考慮使用字典
Sub 按鈕1_Click()
Set d = CreateObject("scripting.dictionary")
Set Rng = Nothing
arr = [a1].CurrentRegion
Application.ScreenUpdating = False
For j = 1 To UBound(arr)
If d.exists(arr(j, 1)) Then
If Rng Is Nothing Then
Set Rng = Cells(j, 1)
Else
Set Rng = Union(Rng, Cells(j, 1))
End If
Else
d(arr(j, 1)) = ""
End If
Next j
If Not Rng Is Nothing Then Rng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
代碼運行前的數據
代碼運行後,僅僅保留不重復項目