您没有给我们足够的信息。
就你而言,A1(“John Doe”)包含两个“o”字符。因此,下面的单元格A2(“John Dowe”)将只有6个字符的共同点。
IF你所说的“同一个字符”是相同位置的同一个字符,那么你在A1和A2之间仍然存在问题。
约翰待办事项Ë
约翰待办事项W¯¯Ë
“W” 和 “e” 不匹配。只有6个字符是相同的。
为我们提供更多信息!
编辑#1
复制并粘贴此代码的模块
Function compareCells(ran As Range) As Variant
Dim numSame As Integer
Dim c As Integer
Dim r As Integer
c = ran.Column 'find selected column
r = ran.Row 'find selected row
Dim a As String
Dim b As String
a = Worksheets("Ark1").Cells(r - 1, c).Value 'string of the cell above
b = Worksheets("Ark1").Cells(r, c).Value 'string of the current cell
Dim aLen As Integer
aLen = Len(a) 'check the length of the a string
Dim i As Integer
For i = 1 To aLen
If Mid(a, i, 1) = Mid(b, i, 1) Then 'if chars in same pos are equal...
numSame = numSame + 1
End If
Next
compareCells = numSame
End Function
编辑#2
Function compareCells(ran As Range) As Variant
Dim numSame As Integer
Dim c As Integer
Dim r As Integer
c = ran.Column 'find selected column
r = ran.Row 'find selected row
Dim a As String
Dim b As String
a = ActiveSheet.Cells(r - 1, c).Value 'string of the cell above
b = ActiveSheet.Cells(r, c).Value 'string of the current cell
Dim aLen As Integer
aLen = Len(a) 'check the length of the a string
Dim i As Integer
For i = 1 To aLen
If Mid(a, i, 1) = Mid(b, i, 1) Then 'if chars in same pos are equal...
numSame = numSame + 1
End If
Next
compareCells = numSame
End Function
使用=compareCells()
并选择只有你想要的细胞与
0以上的单元格进行比较
可能重复的[匹配名称的好算法?](http://stackoverflow.com/questions/7946192/good-algorithm-for-matching-names) – FreeMan 2015-03-31 18:03:48
哇...我在我的头上,但你可能是正确的,我只是不知道如何在Excel中实现任何...谢谢... – manny 2015-04-01 19:30:38
我已经把闪光灯放在那个洞,我认为有一些VB/VBA示例实现,如果你看远远不够。我已经没有了,但是我曾经和一个人一起工作的人实现了Levenshtein距离算法。执行起来很慢,但代码并不是非常困难。我没有做到这一点,因为我现在已经被另一个方向重定向了。 – FreeMan 2015-04-01 19:34:22