我在A列中的数据具有逗号分隔的值(一个/两位数字)。 我需要一种方法来计算两个连续行中的重复次数。
示例数据:
DATA Expected Results
1,2,3,4,5 4
2,3,4,5 2
3,4 0
10,11,40,60,72,75 3
10,40,3,75
请注意,每个列表没有相同数量的值。 A1有5个值,A2有4个值,A3有2个,依此类推。
我将不胜感激。谢谢!
答案 0 :(得分:2)
这是B2
的一种选择:
=IFERROR(SUMPRODUCT(--(1*TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",99)),(ROW(INDEX(AAA:AAA,1):INDEX(AAA:AAA,LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1))-1)*99+1,99))=(TRANSPOSE(1*TRIM(MID(SUBSTITUTE(A3,",",REPT(" ",99)),(ROW(INDEX(AAA:AAA,1):INDEX(AAA:AAA,LEN(A3)-LEN(SUBSTITUTE(A3,",",""))+1))-1)*99+1,99)))))),"")
通过 Ctrl Shift Enter
输入向下拖动...
由于我的Excel版本,图片显示点,因为我无法使用逗号。
从here借来了一些知识
答案 1 :(得分:1)
作为VBA替代
Public Function commonCount(aRng As Range, bRng As Range) As Integer
Dim bArr() As String, aArr() As String, a As Integer, b As Integer
aArr = Split(aRng.Value, ",")
bArr = Split(bRng.Value, ",")
For a = LBound(aArr) To UBound(aArr)
For b = LBound(bArr) To UBound(bArr)
If aArr(a) = bArr(b) Then
commonCount = commonCount + 1
GoTo nexta
End If
Next b
nexta:
Next a
End Function
在B2 commonCount(A2,A3)