試試看
字典(Dictionary)的exists判斷是否為重複,如果字典內找不到才放入,字典內已有的值不放入
Sub Ex()
Dim d As Object
Dim a As Object
Set d = CreateObject("Scripting.Dictionary")
For Each a In Range("a1").CurrentRegion
If Not d.exists(a.Value) Then d.Add a.Value, ""
Next
[g1].Resize(, d.Count) = d.keys
Range([g1], Cells(1, [g1].End(2).Column)).Sort Range("g1"), 1, Orientation:=xlSortRows
Set d = Nothing
End Sub作者: hcm19522 時間: 2020-9-15 14:03