excel - Find which cells have the smallest levenshtein distance -
so, have function return levenshtein distance between 2 strings:
function levenshtein(byval string1 string, byval string2 string) long dim long, j long dim string1_length long dim string2_length long dim distance() long string1_length = len(string1) string2_length = len(string2) redim distance(string1_length, string2_length) = 0 string1_length distance(i, 0) = next j = 0 string2_length distance(0, j) = j next = 1 string1_length j = 1 string2_length if asc(mid$(string1, i, 1)) = asc(mid$(string2, j, 1)) distance(i, j) = distance(i - 1, j - 1) else distance(i, j) = application.worksheetfunction.min _ (distance(i - 1, j) + 1, _ distance(i, j - 1) + 1, _ distance(i - 1, j - 1) + 1) end if next next levenshtein = distance(string1_length, string2_length) end function
i want perform fast comparison between cells in "a" column , return ones have "small" levenshtein distance. how make these comparisons?
do want find combinations of strings have small levenshtein distances or overall how similar/disimilar each string other strings?
if former should work fine:
you copy , paste transposed values create headers(as dale commented). can use conditional formatting highlight lowest results.
or if want actual strings return should able use this:
=if(and(levenshtein($a28,b$27)>0,levenshtein($a28,b$27)<=3),$a28&"/"&b$27,"")
just copy , paste unique values if want returned combinations in single column.
good luck.
Comments
Post a Comment