Problem with message box Find

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
I have the following code which when ran gives me my message box that the "Name Not Found", even though it is there.
Code:
Sub SearchForName()
    Dim Name As Variant
    Dim FindName As Variant
    Name = InputBox(Prompt:="Please Enter the Name You Want to Find", _
    Title:="                          SEARCH")
    If Name = "" Then Exit Sub
    
    Set FindName = Range("B4:B65536").Find(What:=Name, After:=Range("B4"), LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)

    If Not FindName Is Nothing Then
         MsgBox Prompt:="Name Not Found.", Title:="   SORRY"
         Exit Sub
    End If
End Sub

Using the macro recorder to do this Find, I inserted this part
Code:
SearchFormat:=False).Activate
like this
Code:
MatchCase:=False, SearchFormat:=False).Activate
This will find the name but it gives me a Type Mismatch error

What do I have wrong, please
h.h.
 
Erik, I did think of a list as an option, but considering that there will be over 200 names on this sheet and having to create the list "off to the side"
I just thought it would be to much maintenance.
Hi,

it's not my goal to insist or persuade, but just to be sure you are correctly informed
Let it be clear there is no maintenance whatsoever for a listbox.

perhaps you could combine both methods
if more than 1 solution would come up, when writing some characters in your inputbox, then a listbox can be displayed with all matching names

best regards,
Erik
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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