利用字典去重,下面是示例代碼,去除第壹列的重復項Sub Test() '利用字典去重,字典的特性是key值不能重復
Dim Dic, Arr
Dim i As Integer, r As Integer
Dim Str As String
r = Sheet1.Range("A65536").End(xlUp).Row
If r = 1 Then Exit Sub '如果第壹列沒有數據那麽退出程序
Set Dic = CreateObject("scripting.dictionary") '創建字典對象
For i = 1 To r '將第壹列數據添加到字典的key值中
Dic(CStr(Cells(i, 1))) = ""
Next
Arr = Dic.keys '返回字典key的數組
Set Dic = Nothing '銷毀對象
Str = Join(Arr, ",") '將數組中的內容顯示為壹字符串
MsgBox Str
End Sub