Percentage text comparision

Benic

New Member
Hello,

on Sheet I am using this formula to compare 2 strings and show similarity in %:

=(MAX(LEN(A8); LEN(B8)) - levenshtein(A8;B8))/MAX(LEN(A8); LEN(B8))

When I use this code in Macro I receive an error:

"Sub or Function not defined" for MAX.

What is the problem,

thanks

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Tetra201

MrExcel MVP
Use WorksheetFunction.Max(...)

Thank you

You are welcome.

Benic

New Member
The next step in my coding.
 Vent pl.800×800/900/1000, 2 vent/term ×800/900/1000, 2 44% (use formula =(MAX(LEN(A1); LEN(B1)) - levenshtein(A1;B1))/MAX(LEN(A1); LEN(B1)))

<tbody>
</tbody>

I use formula like in this cells to compare texts in A1 and B1.

Now I would like to use this formula in VBA to compare texts in 2 Worksheets like this:
1. Compare text in ActiveSheet (Troskovnik) in column A with text in column A of Sheet Baza_KO
2. If we find match with compatibility > 40 (%) I want to insert number from B2 (Baza_KO) to B2 (Troskovnik)

I have adapt the code but I get the same result to all cell that >40 match,

Code:
``````Sub Usporedba_teksta_POSTOTAK_PODUDARNOSTI()
Dim s1 As Worksheet
Dim s2 As Worksheet
Dim i As Long
Dim j As Long
Dim POST As Long

Set s1 = ActiveWorkbook.Sheets("Troskovnik")
Set s2 = ActiveWorkbook.Sheets("Baza_KO")
'Application.ScreenUpdating = False
'Loop sheet 1
For i = 2 To s1.Cells(Rows.Count, 1).End(xlUp).Row
'Loop sheet 2
For j = 2 To s2.Cells(Rows.Count, 1).End(xlUp).Row
'If match found
POST = (WorksheetFunction.Max(Len(s1.Cells(i, 1)), Len(s2.Cells(j, 1))) - (levenshtein(s1.Cells(i, 1), s2.Cells(j, 1))) / WorksheetFunction.Max(Len(s1.Cells(i, 1)), Len(s2.Cells(j, 1))))

If POST > 40 Then
s1.Cells(i, 2) = s2.Cells(j, 2)
Exit For
End If

Next j
Next i
' Application.ScreenUpdating = True
End Sub``````

what is wrong?

thanks

Replies
10
Views
357
Replies
5
Views
311
Replies
3
Views
121
Replies
6
Views
484
Replies
5
Views
217

1,191,133
Messages
5,984,858
Members
439,921
Latest member
Neocold

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back