ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search not found (https://www.excelbanter.com/excel-programming/370227-search-not-found.html)

kenrose08[_6_]

Search not found
 

Hello!
i entered an item to search in textbox1 and mis encoded it,
and then an error msg appear.
I wan't a msgbox to appear everytime the search failed.

here's the code i'm using:

Private Sub Search_Click()
Set searchRng = Sheets(1).Range("A:A")
With searchRng
Set resultrng = .Find(TextBox1.Text, LookIn:=xlValues)
ComboBox1.Text = ComboBox1.Text & Sheets(1).Range("B" &
_resultrng.Row).Value
End With
End Sub

How do i code it, so that the error msg will be replaced by a msg box
saying "Search Failed". ?

Thanks!


--
kenrose08
------------------------------------------------------------------------
kenrose08's Profile: http://www.excelforum.com/member.php...o&userid=22317
View this thread: http://www.excelforum.com/showthread...hreadid=571124


Tony James[_2_]

Search not found
 
Look at the Find Method example in the VBA help. You need to add an
Else clause to the If statement.

The above code I gave isn't complete, but should give you some clues of
how to fit your requirements into the example.



All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com