ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Capturing an Error (https://www.excelbanter.com/excel-programming/304993-capturing-error.html)

cskgg[_2_]

Capturing an Error
 
Hi all,

This forum is cool and provides superb suggestions - Welldone!!

My current problem:
I have included an "INPUTBOX" which gives me the option of inputting
search string. The choices offered a
OK
and
CANCEL

If I click on CANCEL, the system gives "Runtime error 1004" dialogu
box.

What I wish to do is:
- if the user clicks on CANCEL, then display a message:
"Search cancelled by user".
- if the user does NOT enter any search string (i.e. leaves it
BLANK) but clicks on OK, then, display a message:
"Please input a search string" and display the initial
INPUTBOX again.

Thank you ever so much.
CSKG

--
Message posted from http://www.ExcelForum.com


patrick molloy

Capturing an Error
 
Sub GetSearchString()
Dim search As String
search = Trim(InputBox("Enter Search Text"))

If search = "" Then
MsgBox "Search Cancelled"
Else
' process the search string
End If

End Sub

hitting Cancel or clicking OK without entering any text
both result in the retun of an emoty string. So that's
your first test.

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hi all,

This forum is cool and provides superb suggestions -

Welldone!!

My current problem:
I have included an "INPUTBOX" which gives me the option

of inputting a
search string. The choices offered a
OK
and
CANCEL

If I click on CANCEL, the system gives "Runtime error

1004" dialogue
box.

What I wish to do is:
- if the user clicks on CANCEL, then display a message:
"Search cancelled by user".
- if the user does NOT enter any search string (i.e.

leaves it
BLANK) but clicks on OK, then, display a message:
"Please input a search string" and display the initial
INPUTBOX again.

Thank you ever so much.
CSKGG


---
Message posted from http://www.ExcelForum.com/

.



All times are GMT +1. The time now is 02:48 AM.

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