error message

Jphill

New Member
Joined
Aug 15, 2002
Messages
12
I need to have a message that comes up when there is no match within the search command. Right now the macro stops running and goes to debug. I want it to say part doesn't exist try again. Any suggestions? The code I have looks like this so it needs to be part of this:
Cells.Find(What:=Text1.Text, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi,

Try this (modify to suit your needs):

<pre>
Sub findit()

On Error GoTo MyErrorHdlr
Cells.Find(What:="z", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate

Exit Sub ' so the error handler doesn't run at the end of your code
MyErrorHdlr:
MsgBox "Oops! Text not found."

End Sub
</pre>

HTH
 

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
I use the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Address = "$A$1" Then
If Range("A1").Value = 0 Then
End
Else
Cells.Find(What:=Target.Value, After:=Target, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate
If ActiveCell.Address = Target.Address Then
MsgBox ("No Match Found")
Else
End
End If
End If
End If
End Sub

If this code is inserted into the sheet as an event procedure, It works by entering your search data into cell A1. upon entry, the macro starts automatically, and searches for what you entered into cell A1. If no match is found, and thus the cursor does not move from A1, the code sees this and returns a message "no match found". if however, it does find a match and goes to the location of the match
 

Forum statistics

Threads
1,148,053
Messages
5,744,534
Members
423,881
Latest member
Nguyen Vu

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
Top