VBA - Deleting duplicated in one string which are separated by semicolon

北慕城南 提交于 2021-01-02 04:06:23

问题


I have got in one string like 800 adress emails. They are separated by semicolon. How should I do it to delete duplicates in that string?


回答1:


Please update your question to show what you have already tried. It is very possible that your current code only needs a bit of tweaking.

Below is a more general way to accomplish what you're after, but like I said, there may be an easier way to fix your current code and you won't really learn by copying and pasting code.

Function RemoveDuplicates(rng as Range) As String
    Dim dict As Object
    Dim var As Variant, v As Variant

    Set dict = CreateObject("Scripting.Dictionary")

    var = Split(rng.Value,";")

    For each v in var
        If Not dict.Exists(v) Then
            dict.Add v, v
        End If
    Next v

    RemoveDuplicates = Join(dict.Keys, ";")
End Function


来源:https://stackoverflow.com/questions/44390120/vba-deleting-duplicated-in-one-string-which-are-separated-by-semicolon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!