VBA-删除一个字符串中重复的字符串,这些字符串之间用分号分隔 [英] VBA - Deleting duplicated in one string which are separated by semicolon

查看:72
本文介绍了VBA-删除一个字符串中重复的字符串,这些字符串之间用分号分隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我输入了800封电子邮件这样的字符串.它们之间用分号隔开.如何删除该字符串中的重复项?

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?

推荐答案

请更新您的问题以显示您已经尝试过的内容.您的当前代码很可能只需要进行一些调整.

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

这篇关于VBA-删除一个字符串中重复的字符串,这些字符串之间用分号分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆