我需要比较excel中的两个相邻单元格,并从最左边的字符开始返回两个单元格之间的字符匹配数
A和B栏中的值如下
A1 = Sam Alhoa
A2 = Franklin moore
A3 = Steve jones
A4 = Joe
A5 = Patrick
B1 = Sam Bloggs
B2 = Frank lin dsouza
B3 = Stephen Jones
B4 = Jose
B5 = Patrice
C栏中的结果应为
C1 = 4
C2 = 5
C3 = 3
C4 = 2
C5 = 6
执行此操作的excel公式是什么?
答案 0 :(得分:0)
您可以使用此UDF:
Function compareCharacters(s1 As String, s2 As String) As Integer
Dim i As Integer
For i = 1 To Application.Min(Len(s1), Len(s2))
If Mid(s1, i, 1) <> Mid(s2, i, 1) Then Exit Function
compareCharacters = compareCharacters + 1
Next
End Function
并在任何单元格中调用它:
=compareCharacters(A1,B1)
答案 1 :(得分:0)
试试这个:
=SUM(IFERROR(IF(MID(A1,ROW(INDIRECT("$1:$" & LEN(A1))),1)=MID(B1,ROW(INDIRECT("$1:$" & LEN(B1))),1),1,0),0))
使用 Ctrl + Shift + 输入在C1中作为数组公式输入。