且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除 Excel 单元格中的重复项

更新时间:2023-02-13 17:57:05

答案在这里:https://www.extendoffice.com/documents/excel/2133-excel-remove-duplicate-characters-in-string.html

Function RemoveDupes2(txt As String, Optional delim As String = " ") As String
Dim x
'Updateby20140924
With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
    For Each x In Split(txt, delim)
        If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing
    Next
    If .Count > 0 Then RemoveDupes2 = Join(.keys, delim)
End With
End Function

将上面的代码放在一个模块中

Put the code above in a module

使用 =RemoveDupes2(A2,",")A2 包含由 , 分隔的重复文本您可以更改分隔符

Use =RemoveDupes2(A2,",") A2 contains repeated text separated by , You may change the delimiter