我有几千行数据,需要为每个数据创建唯一的序列。这是一个例子(每个值都在它自己的单元格中):
Text1| Text2| Text2| Text2| Text3| Text3| Text1|
我需要创建一个独特的序列来像这样看
Text1| Text2| Text3| Text1| or
Text1,Text2,Text3,Text1|
有什么想法吗?
答案 0 :(得分:2)
如果第一个Text1
在A1中,那么:
=A1&","&IF(A1<>B1,B1&",","")&IF(B1<>C1,C1&",","")&IF(C1<>D1,D1&",","")&IF(D1<>E1,E1&",","")&IF(E1<>F1,F1&",","")&IF(F1<>G1,G1,"")
可能值得一试。
答案 1 :(得分:1)
作为用户定义的函数
Public Function ClarkeyCat2(ByRef rng As Range, delimIT As String, Optional ByVal trimIT As Boolean = False) As Variant
Dim c As Range
Dim UniqueColl As Collection
Dim tmpValue As Variant
Set UniqueColl = New Collection
If Not trimIT Then
On Error Resume Next
For Each c In rng
If (c.Value <> "") Then
UniqueColl.Add c.Value, c.Value
End If
Next
For k = 1 To UniqueColl.Count
ClarkeyCat2 = ClarkeyCat2 & IIf(ClarkeyCat2 = "", "", delimIT) & UniqueColl.Item(k)
Next
Else
On Error Resume Next
For Each c In rng
If (c.Value <> "") Then
tmpValue = Trim(c.Value)
UniqueColl.Add tmpValue, tmpValue
End If
Next
For k = 1 To UniqueColl.Count
ClarkeyCat2 = ClarkeyCat2 & IIf(ClarkeyCat2 = "", "", delimIT) & UniqueColl.Item(k)
Next
End If
End Function
像这样使用
更新已更新,可选择从单元格条目中删除无关的空白区域,然后再决定条目是否唯一。默认行为是不剥离空格。使用可选的布尔第三参数设置。