ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Error (https://www.excelbanter.com/excel-programming/286280-if-error.html)

mike

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.

Chris Putzig

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.




Chip Pearson

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.





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

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