error message if nothing is found

gb123

New Member
Joined
Mar 21, 2012
Messages
5
I found this very simple code find method but I need to have it give an error message when it cannot find what was entered into the input box. The message box should have an OK button that will return back to the input box so the user can try again.

Sub FindMe()
Cells.Find(What:=InputBox("Please enter SKU", "Search"), _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try:

Code:
Sub FindMe()
Dim rFound As Range

find_cell:
Set rFound = 
Cells.Find(What:=InputBox("Please enter SKU", "Search"), _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False)

If Not rFound Is Nothing Then
  MsgBox "Value not found!"
  Goto find_cell
End If

rFound.Activate
End Sub
 
Upvote 0
thanks for the suggestion. I tried and it did not work. the error mssg pops up no matter what I put in. And if a place some gibberish like "asdfasd" it gives me a runtime error. the original version did find a value and anything that was similar.

Also, when you hit cancel on the input box it takes you back to the error mssg box instead of closing.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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