View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Henrietta Horne Henrietta Horne is offline
external usenet poster
 
Posts: 15
Default Magic Excel function or UDF?

On Tue, 11 Jan 2011 11:46:14 -0500, GS wrote:

Henrietta Horne explained on 1/11/2011 :
I need check a list of words against an alphabet (a string of letters)
and return the index of the letter in the word that is the highest in
the alphabet.

For example, for the alphabet is "etaoin", these words would return
these indices:

Word Index
to 4
ate 3
ten 6
neat 6
tee 2

Is there some magic Excel function that will do this?

If not, can someone post the guts of a search loop to select each
letter in sWord and find the index in sAlphabet?

The actual alphabet will have all 26 letters and might look like this:

etaoinsrhldcumgfpwybvkjxzq


Try this...

Function GetHighIndex(sWord As String, sAlphabet As String) As Integer
Dim i As Integer, iPos As Integer
For i = 1 To Len(sWord)
iPos = InStr(1, sAlphabet, Mid$(sWord, i, 1), vbTextCompare)
If iPos GetHighIndex Then GetHighIndex = iPos
Next
End Function


Thank you so much. You and Clif had essentially the same solution.
Hugs.