ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to deal with Find when nothing is found (https://www.excelbanter.com/excel-programming/326127-how-deal-find-when-nothing-found.html)

Mike

How to deal with Find when nothing is found
 
I have this in my Sub.

Cells.Find(what:=LOC, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

If the string is not found, it runs an error, giving the user the option to
debug. How can I have it comeback and say the string was not found and then
end the sub? Am I making sense? Thanks.

ben

How to deal with Find when nothing is found
 
hi
dim findnotfind as range
set findnotfind = Cells.Find(what:=LOC, After:=ActiveCell, LookIn:=xlValues,
LookAt:=xlPart,
SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
if findnotfind is nothing then
msgbox "I'm sorry the value was not found"
exit sub
end if


"Mike" wrote:

I have this in my Sub.

Cells.Find(what:=LOC, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

If the string is not found, it runs an error, giving the user the option to
debug. How can I have it comeback and say the string was not found and then
end the sub? Am I making sense? Thanks.



All times are GMT +1. The time now is 07:50 AM.

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