我在 Excel 中有一列,其中有一些用逗号分隔的字符串。例如:
塞格,特尔,夸,塞格
性别
萨布,萨布
塞格
多姆·塞格
(有些行可以为空)
我想计算每行中不同字符串的数量,在上面的例子中,我希望输出为:
Seg: 2, Ter: 1, Qua: 1
姓名:1,性别:1
萨布:2
段:1
主:1,分段:1
有没有办法在 Excel 中执行此操作?
答案1
尝试以下操作用户定义函数:
Public Function Components(sIN As String) As String
Dim c As Collection, bry(), L As Long
L = Len(sIN)
Set c = New Collection
ary = Split(sIN, ", ")
On Error Resume Next
For Each a In ary
c.Add a, CStr(a)
Next a
On Error GoTo 0
ReDim bry(1 To c.Count)
For i = 1 To c.Count
bry(i) = c.Item(i)
Kount = (L - Len(Replace(sIN, bry(i), ""))) / Len(bry(i))
Components = Components & bry(i) & ":" & Kount & ", "
Next i
Components = Left(Components, Len(Components) - 2)
End Function