#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default If Error

Hi.

The following code finds a text string in
worksheet "Blank 1". I need to have a msgbox come-up if
the text is not found. How should I program so that an
error won't throw the user into the module?

myRow = Worksheets("Blank 1").Rows.Find
(What:=AgentName).Row + 1

Thanks,
Mike.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default If Error

Try this:

On Error Resume Next 'disable error
myRow = Worksheets("Blank 1").Rows.Find _
(What:=AgentName).Row + 1
If myRow 0 Then
'do something
MsgBox myRow
Else
MsgBox AgentName & " not found"
End If
On Error GoTo 0 'reset error

"Mike" wrote in message
...
Hi.

The following code finds a text string in
worksheet "Blank 1". I need to have a msgbox come-up if
the text is not found. How should I program so that an
error won't throw the user into the module?

myRow = Worksheets("Blank 1").Rows.Find
(What:=AgentName).Row + 1

Thanks,
Mike.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default If Error

Mike,

Try something like

Dim FoundCell As Range
Set FoundCell = Worksheets("Blank 1").Find(What:=AgentName)
If FoundCell Is Nothing Then
Msgbox "Not Found"
Else
MyRow = FoundCell.Row
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Mike" wrote in message
...
Hi.

The following code finds a text string in
worksheet "Blank 1". I need to have a msgbox come-up if
the text is not found. How should I program so that an
error won't throw the user into the module?

myRow = Worksheets("Blank 1").Rows.Find
(What:=AgentName).Row + 1

Thanks,
Mike.



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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Error of slope taking into account error of the data points cer144 Excel Worksheet Functions 5 July 7th 08 07:26 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


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

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

About Us

"It's about Microsoft Excel"