"利用字典去重,下面是示例程式碼,去除第一列的重複項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 StrEnd Sub
"利用字典去重,下面是示例程式碼,去除第一列的重複項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 StrEnd Sub