ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If not found get a message (https://www.excelbanter.com/excel-programming/325577-if-not-found-get-message.html)

Fgomez

If not found get a message
 
I am using this Macro:
Acct = Application.InputBox(prompt:="Enter Account", Type:=1)
Columns("A:A").Select
Selection.Find(What:=Acct, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

To find an account # in Column A ( Ther are about 1700 and is a report
downloaded from a database, the report contains different information
regarding the account from Column B to E.
My problem is that if I input an account that is not in the report it stop
the Macro and does not continue.
Is it possible to include in the report a message saying "Account not found"
with a button to cancel the operation instead of getting an error.

Thank you in advance

Fernando



Don Guillett[_4_]

If not found get a message
 
try this. You can also probably delete many of the un-necessary parameters
Sub notfoundmsg()
On Error GoTo notfound
Acct = Application.InputBox(prompt:="Enter Account", Type:=1)
Columns("A:A").Find(What:=Acct, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select
Exit Sub
notfound: MsgBox "Not found"
End Sub
Sub notfoundmsgCLEANED()
On Error GoTo notfound
Acct = Application.InputBox(prompt:="Enter Account")
Columns("A:A").Find(Acct, LookAt:=xlPart).Select
Exit Sub
notfound: MsgBox "Not found"
End Sub
--
Don Guillett
SalesAid Software

"Fgomez" wrote in message
...
I am using this Macro:
Acct = Application.InputBox(prompt:="Enter Account", Type:=1)
Columns("A:A").Select
Selection.Find(What:=Acct, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,

_
MatchCase:=False, SearchFormat:=False).Activate

To find an account # in Column A ( Ther are about 1700 and is a report
downloaded from a database, the report contains different information
regarding the account from Column B to E.
My problem is that if I input an account that is not in the report it stop
the Macro and does not continue.
Is it possible to include in the report a message saying "Account not

found"
with a button to cancel the operation instead of getting an error.

Thank you in advance

Fernando





Harald Staff

If not found get a message
 
Hi Fernando

One way among several:

Sub test()
Dim Acct As Double
Dim Here As Range
Acct = Application.InputBox(prompt:="Enter Account", Type:=1)
On Error Resume Next
Set Here = Columns("A:A").Find(What:=Acct, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Here Is Nothing Then
MsgBox "No cigar"
Exit Sub
End If
Here.Select
MsgBox "Working on " & Here.Address & " further"
MsgBox Here.Address & " is great you know", vbInformation
End Sub

Note, I changed xlPart to xlWhole, otherwise 800 would be found in a cell
containing 8000. Probably not good for account numbers.

HTH. Best wishes Harald

"Fgomez" skrev i melding
...
I am using this Macro:
Acct = Application.InputBox(prompt:="Enter Account", Type:=1)
Columns("A:A").Select
Selection.Find(What:=Acct, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,

_
MatchCase:=False, SearchFormat:=False).Activate

To find an account # in Column A ( Ther are about 1700 and is a report
downloaded from a database, the report contains different information
regarding the account from Column B to E.
My problem is that if I input an account that is not in the report it stop
the Macro and does not continue.
Is it possible to include in the report a message saying "Account not

found"
with a button to cancel the operation instead of getting an error.

Thank you in advance

Fernando






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

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