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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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