我在两个对应的列中有一行 10,000 个名称,每列 10,000 个。 A 列中的每个单元格都对应于 B 列中的相邻单元格。我想进行模糊匹配并获得所有这些单元格与相邻单元格的兼容性分数。我不希望它搜索整列与整列,只是相邻的单元格,我似乎无法使用模糊匹配 Excel 插件来做到这一点,想法?
例子:
Column A: Column B: Value:
Apple Aplle 80%
Banana Banana 100%
Orange Ornge 85%
最佳答案
嗯,我不知道模糊匹配插件,但您可以使用 UDF 完成类似于您的要求。
基于您的示例数据的类似内容
Function FuzzyComparision(String1 As String, String2 As String) As Double
Dim intStringLength As Integer
Dim dblScore As Double
Dim dblUnitScore As Double
Dim intCounter As Integer
intStringLength = WorksheetFunction.Max(Len(String1), Len(String2))
dblUnitScore = 1 / intStringLength
dblScore = 0#
For intCounter = 1 To intStringLength
If Mid(UCase(String1), intCounter, 1) = Mid(UCase(String2), intCounter, 1) Then
dblScore = dblScore + dblUnitScore
Else
If Len(String1) <> Len(String2) And intCounter < intStringLength Then
If Mid(UCase(String1), intCounter + 1, 1) = Mid(UCase(String2), intCounter, 1) Then
dblScore = dblScore + dblUnitScore
End If
End If
End If
Next
FuzzyComparision = dblScore
End Function
当然,可以根据需要进一步即兴进行比较。 让我知道是否有帮助
编辑:正如 Grade Bacon 所指出的(感谢您的观察),对于丢失的字母,这并不像预期的那样有效。我对该函数进行了一些调整,以进行不区分大小写的比较并补偿丢失的字母,如示例中所示。
即使有效,效用也取决于可接受的分数偏差 +/-。 OP 可能会有所启发。
关于excel - 如何模糊匹配相邻的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33825419/