在A列中,我具有以下数据集。
A1 :TR029A/TR029B/TR045A/TR045B
A2 :TR028A/TR028B/TR052A
A3 :TR035A/TR035B
A4 : TR045B/TR065A
可以通过以下任何方式生成B列数据。
B1: TR029/TR045
B2: TR028/TR052
B3: TR035
B4: TR045/TR065
答案 0 :(得分:1)
我想,如果您需要这种控制级别,则必须使用VBA创建excel函数
将此VBA代码复制到打开的窗口中,以创建所需的新功能GenChars:
Option Explicit
Function GenChars(value As String)
' an array of individual elements that were delemited by "/"
Dim xs() As String
xs = Split(value, "/")
' remove the last character from each element or replace it with @ if it would be a duplicate
Dim i As Long
For i = LBound(xs) To UBound(xs)
Dim x As String
x = xs(i)
x = Left$(x, Len(x) - 1) ' remove last char
If ArrayContains(xs, x) Then x = "@" ' replace duplicate elements with @
xs(i) = x
Next i
Dim value2 As String
' new value with duplicates
value2 = Join(xs, "/") ' put the elements back into 1 value
' remove @ that was used instead of duplicates
value2 = Replace(value2, "/@", "") ' remove occurrences of /@ (1st element is never duplicate)
GenChars = value2
End Function
' whether array xs contains element y
Function ArrayContains(xs As Variant, y As Variant) As Boolean
ArrayContains = False
Dim x As Variant
For Each x In xs
If x = y Then ArrayContains = True
Next x
End Function
答案 1 :(得分:1)