Help with my VBA. Using input box to find name. Need to find partials and deal with duplicates

ILMWT

New Member
Joined
Dec 9, 2014
Messages
35
Here is the VBA
<code style="font-family: monospace, monospace; margin: 0px 2px; border: 0px; border-radius: 2px; word-break: normal; display: block; font-size: 1em; line-height: 1.42857142857143em; padding: 0px !important; background-color: transparent;">Sub FindName()

Dim FindString As String

Dim Rng As Range

FindString = InputBox("Enter Persons Name")

If Trim(FindString) <> "" Then

With Sheets("Tracking").Range("D:D")

Set Rng = .Find(What:=FindString, _

After:=.Cells(.Cells.Count), _

LookIn:=xlValues, _

LookAt:=xlWhole, _

SearchOrder:=xlByRows, _

SearchDirection:=xlNext, _

MatchCase:=False)

If Not Rng Is Nothing Then

Application.Goto Rng, True

Else

MsgBox "Nothing found"

End If

End With

End If

End Sub
</code>What I need it to do is find partials. If I am searching for Doe, Jane I would like to be able to type in "Doe" or "Jane" to find the name. Also, if there are more than 1 Janes, how do I deal with this?
Thank you. Will credit with verified solutions.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
This code will find partial matches and duplicate entries...

Code:
Sub FindName()
Dim rF As Range, rD As Range
Dim sFAddr As String
Dim FindString As String


    FindString = InputBox("Enter Persons Name")
    Application.ScreenUpdating = False
    With Sheets("Tracking").Range("D:D")
        Set rF = .Find(What:=FindString, Lookat:=xlPart, SearchOrder:=xlByRows, _
                       SearchDirection:=xlNext, MatchCase:=False)
        If Not rF Is Nothing Then
            Set rD = rF
            sFAddr = rF.Address
            Set rF = .FindNext(after:=rF)
            Do Until rF.Address = sFAddr
                Set rD = Application.Union(rD, rF)
                Set rF = .FindNext(after:=rF)
            Loop
        End If
    End With
    If Not rD Is Nothing Then rD.Select
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,774
Messages
6,132,651
Members
449,740
Latest member
Stevejhonsy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top