企業が一致する程度を示すユーザー定義関数を作成しました。この関数は、thisRange として使用する範囲が行 2800 以下である限り、非常にうまく機能します。4000 社の企業のリストがあり、それらを 2800 を超える行に含めようとすると、機能しません。範囲はそれほど大きくありませんか?この問題を解決する方法はありますか?
コードは次のとおりです。
Function bestMatch(company As String, thisRange As Range) As String
Dim min As Double, nextMin As Double
Dim cell As Range
Dim score As Double
Dim best As String, str As String, nextBest As String
min = 99999
nextMin = 99999
For Each cell In thisRange.Cells
str = cell.Value
substr1 = Left(str, 1)
substr2 = Left(company, 1)
score = Leven(company, str)
If score < min And substr1 = substr2 Then
min = score
best = str
ElseIf score = min And substr1 = substr2 Then
min = score
best = str + " && " + best
ElseIf score > min And score <= nextMin And substr1 = substr2 Then
nextMin = score
nextBest = str
min = min
best = best
End If
Next
If min > 15 Then
bestMatch = "No Match Found"
ElseIf min <= 15 Then
bestMatch = "1. " + best + " 2. " + nextBest
End If
End Function