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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,218,595
Messages
6,143,386
Members
450,484
Latest member
ChrisMac1

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