1、打開要進行數據處理的表格,
2、按ALT+f11,進入VBE程序操作頁面,
3、將鼠標下移,右鍵彈出如圖,
4、選擇插入-模塊,
5、鼠標向右移動,將如下代碼寫入:
Sub test()
Dim d As Object
Dim r%, i%
Dim arr
Set d = CreateObject("scripting.dictionary")
With Worksheets("sheet1")
r = .Cells(.Rows.Count, 3).End(xlUp).Row
arr = .Range("c2:d" & r)
For i = 1 To UBound(arr)
d.RemoveAll
For j = 1 To Len(arr(i, 1))
ch = Mid(arr(i, 1), j, 1)
d(ch) = ""
Next
arr(i, 2) = Join(d.Keys, "")
Next
.Range("d2").Resize(UBound(arr), 1) = Application.Index(arr, 0, 2)
End With
End Sub
6、按F5,運行代碼,後返回工作表,會發現單元格中的重復字符已經被去掉。