ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Trapping (https://www.excelbanter.com/excel-programming/353318-error-trapping.html)

Rafi

Error Trapping
 
How do I generate an error message such as "Macro will be aborted - The Find
Function cannot return a valid value" if the string "Cross" is not found in
the selection.

Selection.Find(What:="Cross", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Thanks

Bob Phillips[_6_]

Error Trapping
 
Set cell = Selection.Find(What:="Cross", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
MsgBox "Macro will be aborted - The Find Function cannot return a valid
value"
Exit sub
end if

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Rafi" wrote in message
...
How do I generate an error message such as "Macro will be aborted - The

Find
Function cannot return a valid value" if the string "Cross" is not found

in
the selection.

Selection.Find(What:="Cross", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Thanks




Jim Thomlinson[_5_]

Error Trapping
 
use a range object and test if it is nothing something like this...

dim rng as range

set rng = Selection.Find(What:="Cross", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

if rng is nothing then
msgbox "Macro will be aborted - The Find Function cannot return a valid
value"
else
rng.activate
end if
--
HTH...

Jim Thomlinson


"Rafi" wrote:

How do I generate an error message such as "Macro will be aborted - The Find
Function cannot return a valid value" if the string "Cross" is not found in
the selection.

Selection.Find(What:="Cross", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Thanks


Eric_MUC

Error Trapping
 
Hi Rafi,

you could use this:

Public Sub Find_Cross()
Dim rngFound As Range

Set rngFound = Selection.Find(What:="Cross", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If rngFound Is Nothing Then
MsgBox "Macro will be aborted - The Find Function cannot return a
valid value"
Else
rngFound.Activate
End If

End Sub

Did this help you?

Best wishes,
Eric


"Rafi" wrote:

How do I generate an error message such as "Macro will be aborted - The Find
Function cannot return a valid value" if the string "Cross" is not found in
the selection.

Selection.Find(What:="Cross", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Thanks



All times are GMT +1. The time now is 06:18 AM.

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