Percentage text comparision

Benic

New Member
Joined
Aug 2, 2013
Messages
35
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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The next step in my coding.
Vent pl.800×800/900/1000, 2 vent/term×800/900/1000, 244% (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
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,727
Members
449,049
Latest member
MiguekHeka

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top