Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Trapping from WSH Tom Chau Excel Discussion (Misc queries) 1 August 25th 06 04:21 AM
Error trapping Steve Excel Programming 2 October 17th 05 10:52 PM
Error Trapping Adrian Excel Programming 0 January 31st 05 06:16 PM
error trapping [email protected] Excel Programming 2 January 20th 05 10:07 PM
error trapping libby Excel Programming 5 November 25th 03 10:57 PM


All times are GMT +1. The time now is 01:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"