Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find similar strings in a range

Status
Not open for further replies.

davedave24

Programmer
Aug 26, 2010
113
GB
I'm using the following code to find a string in a range, to see if the user enters a duplicate customer name:

Code:
 Dim rngFind As Range
    
    With Workbooks("Aug10").Sheets("Customers").Range("A:A")
        Set rngFind = .Find(textCustomerName.Text, , xlValues)
    End With
 
    If rngFind Is Nothing Then
         'do my stuff
    Else
         'alert the user to a duplicate
    End If

Some of the names contain characters such as periods and hyphens. Others contain spaces. Is there a function to detect similar strings? For example:

A Hart
AHart
A-Hart
A.Hart

ABC
A.B.C.
A-B-C
A B C
 
edit:

I've switched to a better method

Code:
    Dim p As Long
    
    p = Range("A:A").Find(textCustomerName, Range("A1"), xlValues, xlWhole, xlByColumns, xlNext).Row
    If p = 0 Then 'not found
        MsgBox "not found"
    Else
     MsgBox "Found " & textCustomerName & " at row : " & p
    End If

This matches the string exactly, whereas the first method I had picked the string out from the middle of other strings.

Still, would there be a simple way to get it to find similar strings like above?
 
Just an idea, how about adding another column which strips out all non-alphanumeric characters in the customer name? Then you can search on that column.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top