Fast string comparison
"Claus Busch" wrote:
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)
Hi Claus. Unfortunately, I will not be comparing strings that
exist on a spreadsheet. I will be comparings strings that are
stored in String variables. So, for example:
Dim strA as String
Dim strB as String
strA = "apple"
strB = "banana"
If myComp(strA, strB) = True then
'
End if
I apologize for the bad explanation. My table above looked
like a spreadsheet, but really it was just a sample chart of
example data. So, I need a function that does not rely on
data stored in a spreadsheet. So sorry about that.
|