excel vba 字符相似度问题

如图,字符相似度问题,列与列之间的遍历比较,跪求解答
这有个类似的vba代码,但是仅是两单元格间的平行比较 ,而我需要的是某一单元格与另一列的比较返回最大相似度,网址如下:http://blog.csdn.net/dyfgs/article/details/7177088

Sub similar()

Dim s,m
For i=2 to Columns(3).Find("*", , , , 1, 2).row
    For j=2 to Columns(1).Find("*", , , , 1, 2).row
        s=sim(Range("B" & i),Range("A" & j))
        If j=2 Then
            m=s
        Else 
            If s>m Then
                m=s
            Else
                If m=1 Then
                    Exit For
                End If
            End If
        End If
    Next j
    Range("C" & i)= m
Next i

End Sub


Private Function min(one As Integer, two As Integer, three As Integer)  

    min = one  

    If (two < min) Then  

     min = two  

    End If  

    If (three < min) Then  

     min = three  

    End If  

End Function  

  

Private Function ld(str1 As String, str2 As String)  

Dim n, m, i, j As Integer  

Dim ch1, ch2 As String  

    n = Len(str1)  

    m = Len(str2)  

    Dim temp As Integer  

    If (n = 0) Then  

        ld = m  

    End If  

    If (m = 0) Then  

        ld = n  

    End If  

Dim d As Variant  

ReDim d(n + 1, m + 1) As Variant  

    For i = 0 To n  

        d(i, 0) = i  

    Next i  

    For j = 0 To m  

        d(0, j) = j  

    Next j  

    For i = 1 To n  

        ch1 = Mid(str1, i, 1)  

        For j = 1 To m  

            ch2 = Mid(str2, j, 1)  

            If (ch1 = ch2) Then  

            temp = 0  

            Else  

                temp = 1  

            End If  

            d(i, j) = min(d(i - 1, j) + 1, d(i, j - 1) + 1, d(i - 1, j - 1) + temp)  

        Next j  

    Next i  

    ld = d(n, m)  

End Function  

  

Public Function sim(str1 As String, str2 As String)  

    Dim ldint As Integer  

    ldint = ld(str1, str2)  

    Dim strlen As Integer  

    If (Len(str1) >= Len(str2)) Then  

        strlen = Len(str1)  

    Else  

        strlen = Len(str2)  

    End If  

    sim = 1 - ldint / strlen  

End Function  

追问

实时错误91 对象变量或with块变量未设置,调试如下,本人小白劳烦高手解决

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网