View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Case sensitive VBA Match

Use StrComp to compare two strings:

S1 = "abc"
S2 = "ABC"
If StrComp(S1, S2, vbBinaryCompare) = 0 Then
' exact match
Else
' not a match
End If

The vbBinaryCompare means that the match is case sensitive -- "abc" <
"ABC". You can change it to vbTextCompare to make the comparison case
insensitive -- "abc" = "ABC".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 14 May 2009 05:19:01 -0700, PBezucha
wrote:

A recent thread showed the way how to do match with Exact function in Excel.
It reminded me of the need to improve my ancient VBA matches made clumsily by
sequel constraining the remainder of the (not very long) database or even
browsing it as a whole (first occurrence sufficient).

Unfortunately there is no WorksheetFunction.Exact – otherwise it would look
like this:

Function MatchRow(DBName As String, Sought As Variant) As Long
Dim DB As Range
With Worksheets(DBName)
Set DB = Range(.Range("A1"), .Range("A1").End(xlDown))
MatchRow = Application.WorksheetFunction.Match(True, _
Application.WorksheetFunction.Exact(Sought, DB), 0)
End With
End Function

Such a simple task should be very common, yet, and still I have not
succeeded in finding a smart DG solution. What are your better ways?

Sincerely