Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Try this small UDF:
Function divergence(r1 As Range, r2 As Range) As Integer v1 = r1.Value v2 = r2.Value divergence = 0 i = Application.WorksheetFunction.Max(Len(v1), Len(v2)) For j = 1 To i ch1 = Mid(v1, j, 1) ch2 = Mid(v2, j, 1) If ch1 = ch2 Then Else divergence = j Exit Function End If Next End Function If the two strings exactly match, it will return a zero. It will also catch case changes as well. -- Gary''s Student - gsnu2007i "Greg Lovern" wrote: I have two strings that start with the same characters, but at some unknown and varying point they begin to differ. I want the position number of the first non-matching character. For example: -- table and chair -- table plus chair -- position of first non-matching character is 7 (the "a" in "and", and the "p" in "plus"). In the above example, both strings start out "table ", then start to differ beginning with the 7th character. How can I return the position of the first non-matching character, which in this example is 7? Thanks, Greg |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
return a character at a certain position in a string of text | Excel Worksheet Functions | |||
Return position of 2nd, 3rd, ect occurrence of a character in a st | Excel Discussion (Misc queries) | |||
Insert a special character in 1st and last position into a cell | New Users to Excel | |||
sort on character position | Excel Worksheet Functions | |||
Return position for each matching value in entire workbook? | Excel Worksheet Functions |