View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Fast string comparison

Hi Robert,

Am Fri, 15 May 2015 05:35:23 -0700 schrieb Robert Crandal:

A B Value
--------- ------- -------
apple banana True
banana apple False
winner wins True
WiNneR winS True
right-handed left-handed False
apple apple False (equal)


try:
Function myComp(myRng As Range) As Boolean
Dim rngC As Range
Dim i As Long

For Each rngC In myRng
For i = 1 To Len(rngC)
If LCase(Mid(rngC, i, 1)) < _
LCase(Mid(rngC.Offset(, 1), i, 1)) Then
myComp = IIf(Asc(LCase(Mid(rngC, i, 1))) < _
Asc(LCase(Mid(rngC.Offset(, 1), i, 1))), True, False)
Exit For
End If
Next
Next
End Function

and call the function in the sheet with
=myComp(A1)

If nesessary you have to insert a Replace for hyphens and single quotes.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional