Я пытаюсь получить n-й аналог диапазона в сравнении с текстом.Функция Similarity
возвращает процентное сходство между двумя текстами.
Function SimilarText(ByVal CompareText As String, _
ByRef TargetCompare As Range, _
Optional ByVal RankSimilarity As Integer = 1) As Long
Dim compareResults() As Long
ReDim compareResults(RankSimilarity)
Dim simiResult As Single
Dim smallestIndex As Integer
Dim result As String
Debug.Print (CompareText)
For Each cell In TargetCompare
simiResult = Similarity(cell.Value, CompareText)
Debug.Print (simiResult)
If simiResult > Application.Min(compareResults) Then
smallestIndex = Application.Match(Application.Min(compareResults), compareResults, 0) - 1
Debug.Print ("Index:" & smallestIndex)
compareResults(smallestIndex) = CLng(simiResult)'//This doesnt seem to do anything. I tried without the conversion but still nothing.
Debug.Print ("Smallest after update:" & compareResults(smallestIndex)) '//This always 0
End If
Next cell
SimilarText = Application.Min(compareResults) '//So this is also alway 0
End Function
Я ожидаю, что элемент массива будет обновляться после каждой ячейки, например '(0.22,0.44), но результат, кажется, всегда0.