MIN with VBA function throws #N/A

narnian_uk

New Member
Joined
Jul 28, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm using the Damerau-Levenshtein function set out on GitHub - physics515/VBA-Common-Library: A library of common VBA functions., which creates a public function called "damerau":

This function takes two strings of any length and calculates the Damerau-Levenshtein Distance between them. Damerau-Levenshtein Distance differs from Levenshtein Distance in that it includes an additional operation, called Transpositions, which occurs when two adjacent characters are swapped. Thus, Damerau-Levenshtein Distance calculates the number of Insertions, Deletions, Substitutions, and Transpositons needed to convert string1 into string2. As a result, this function is good when it is likely that spelling errors have occured between two string where the error is simply a transposition of 2 adjacent characters.

The function works fine; for example

Excel Formula:
=damerau("Test", "Tset")

will give a result of 1 because one character swap is required. Similarly,

Excel Formula:
=BYROW(N3#, LAMBDA(name, damerau(A2, name)))

where N3# is a list of names and A2 contains a single name will produce the expected spilled array of DL values ({0; 13; 12; 13; etc.}). However,

Excel Formula:
=MIN(BYROW(N3#, LAMBDA(name, damerau(A2, name))))

produces an #N/A, and I can't work out why; I would have expected it to yield a value of 0. Any thoughts...?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
It seems to be something to do with the way BYROW outputs the data. If you wrap that in N() before using MIN() it seems to work:

Excel Formula:
=MIN(N(BYROW(N3#, LAMBDA(name, damerau(A2, name)))))
 
Upvote 0
Solution
It seems to be something to do with the way BYROW outputs the data. If you wrap that in N() before using MIN() it seems to work:

Excel Formula:
=MIN(N(BYROW(N3#, LAMBDA(name, damerau(A2, name)))))

You learn something new every day. Great - thank you!
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,395
Members
449,446
Latest member
CodeCybear

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