如何删除与/?分隔的单元格中的重复值? [英] How do I remove duplicate values in a cell seperated with a /?

查看:120
本文介绍了如何删除与/?分隔的单元格中的重复值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  b1 = E4I8 / E4I8 / E4I8 / E4I8 
b2 = D3B2 / B30C1 / D3B2 / D3B2 / D3B2 / B30C1


multiple / xxxx /

如何在同一个单元格中删除这些重复的文本字符串?



谢谢

解决方案

此函数使用字典的键从传入的字符串中构建一个唯一的部分列表(添加对 Microsoft Scripting Runtime ):

 公共功能UniqueParts(separator As String,toParse As String)As String 
Dim d As New Scripting.Dictionary,part As Variant,i As Integer
对于每个部分在拆分(toParse,separator)
d(part)= 1
下一个
UniqueParts = Join(d.Keys,/)
结束函数

你可以在Excel公式中使用此功能:

  = UniqueParts(/,E4I8 / E 4I8 / E4I8 / E4I8)

或单元格引用:

  = UniqueParts(/,B2)

您还可以在宏中遍历一系列单元格。


I have multiple cells in excel that have as follows:

    b1= E4I8/E4I8/E4I8/E4I8
    b2=D3B2/B30C1/D3B2/D3B2/D3B2/B30C1


    multiple /xxxx/ 

How do I remove these duplicate text strings in the same cell?

Thank you

解决方案

This function uses the keys of a dictionary to build a unique list of parts from a passed-in string (add a reference to Microsoft Scripting Runtime):

Public Function UniqueParts(separator As String, toParse As String) As String
    Dim d As New Scripting.Dictionary, part As Variant, i As Integer
    For Each part In Split(toParse, separator)
        d(part) = 1
    Next
    UniqueParts = Join(d.Keys, "/")
End Function

You can use this function in an Excel formula:

=UniqueParts("/","E4I8/E4I8/E4I8/E4I8")

or with a cell reference:

=UniqueParts("/",B2)

You can also use this inside a macro that iterates over a range of cells.

这篇关于如何删除与/?分隔的单元格中的重复值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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