您沒有給我們足夠的信息。
就你而言,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