我有一个单元格,其中包含一长串数字,以逗号和空格分隔。
有些数字重复了,我想知道哪个数字重复最多。
MODE 函数不起作用,似乎设计用于每个值都在其自己的单元格中的范围内。
我需要的示例
Cell with numbers
123, 456, 456
Most frequently repeated value
456
答案1
如果您的价值观是像您显示的数字:
=MODE.SNGL(FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b"))
创建"<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>"
一个 xml 字符串。然后FILTERXML(...,"//b")
返回数字数组。然后MODE.SNGL
返回最大的重复项。
如果是文本或混合:
=INDEX(FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b"),MODE.SNGL(MATCH(FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b"),FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b"),0)))
这次我们使用 Match 返回一个数字数组(其中它与第一个匹配项匹配,在下面的情况下将是1,2,2
)然后MODE_SNGL
将返回2
到 INDEX。
答案2
尝试这个简短的用户定义函数:
Public Function splitt(s As String) As Variant
Dim mx As Long, i As Long, j As Long, mxkp As Long
arr = Split(s, ", ")
mx = 0
mxkp = 0
splitt = arr(0)
For i = 0 To UBound(arr)
v = arr(i)
mx = 0
For j = 1 To UBound(arr)
If v = arr(j) Then mx = mx + 1
Next j
If mx > mxkp Then
mxkp = mx
splitt = v
End If
Next i
End Function