Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default If Cells.Find finds something

Excel Experts,

My code checks if a transaction is done correctly, and if it is not, puts a
formula that displays the word "Violation" in a cell next to the transaction.

In the following section, the code checks if the word "Violation" is
displayed anywhere in the sheet. If there are no Violations, it displays a
message box stating this, and if there is a violation, it goes to the first
cell that displays "Violation".

<<start code
On Error GoTo errTrap

Cells.Find(What:="Violation", LookIn:=xlValues).Activate

errTrap:
Answer = MsgBox("No Violations Found", vbOKOnly)

<<end code

What I'd like to add is code that, if "Violation" was found, pops up a
message box stating, "Violation Found".

Something like,

If the line below finds something (or doesn't produce an error)
"Cells.Find(What:="Violation", LookIn:=xlValues).Activate"
MsgBox("Violation Found", vbOKOnly)

What code would do this?

Thanks in advance.

Alan
--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default If Cells.Find finds something

When using find I always find it helpful to use a range object to let me know
if and or what I found

dim rngFound as range

set rngFound = Cells.Find(What:="Violation", LookIn:=xlValues)

if rngfound is nothing then
msgbox "No Violations were found"
else
msgbox "A violation was found at " & rngfound.address
rngfound.select
end if
--
HTH...

Jim Thomlinson


"achidsey" wrote:

Excel Experts,

My code checks if a transaction is done correctly, and if it is not, puts a
formula that displays the word "Violation" in a cell next to the transaction.

In the following section, the code checks if the word "Violation" is
displayed anywhere in the sheet. If there are no Violations, it displays a
message box stating this, and if there is a violation, it goes to the first
cell that displays "Violation".

<<start code
On Error GoTo errTrap

Cells.Find(What:="Violation", LookIn:=xlValues).Activate

errTrap:
Answer = MsgBox("No Violations Found", vbOKOnly)

<<end code

What I'd like to add is code that, if "Violation" was found, pops up a
message box stating, "Violation Found".

Something like,

If the line below finds something (or doesn't produce an error)
"Cells.Find(What:="Violation", LookIn:=xlValues).Activate"
MsgBox("Violation Found", vbOKOnly)

What code would do this?

Thanks in advance.

Alan
--
achidsey

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default If Cells.Find finds something


Jim,

Works great. Thanks.

Alan

--
achidsey


"Jim Thomlinson" wrote:

When using find I always find it helpful to use a range object to let me know
if and or what I found

dim rngFound as range

set rngFound = Cells.Find(What:="Violation", LookIn:=xlValues)

if rngfound is nothing then
msgbox "No Violations were found"
else
msgbox "A violation was found at " & rngfound.address
rngfound.select
end if
--
HTH...

Jim Thomlinson


"achidsey" wrote:

Excel Experts,

My code checks if a transaction is done correctly, and if it is not, puts a
formula that displays the word "Violation" in a cell next to the transaction.

In the following section, the code checks if the word "Violation" is
displayed anywhere in the sheet. If there are no Violations, it displays a
message box stating this, and if there is a violation, it goes to the first
cell that displays "Violation".

<<start code
On Error GoTo errTrap

Cells.Find(What:="Violation", LookIn:=xlValues).Activate

errTrap:
Answer = MsgBox("No Violations Found", vbOKOnly)

<<end code

What I'd like to add is code that, if "Violation" was found, pops up a
message box stating, "Violation Found".

Something like,

If the line below finds something (or doesn't produce an error)
"Cells.Find(What:="Violation", LookIn:=xlValues).Activate"
MsgBox("Violation Found", vbOKOnly)

What code would do this?

Thanks in advance.

Alan
--
achidsey

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
formula finds values in apparently blank cells Daniel Collison Excel Worksheet Functions 1 January 12th 10 02:34 PM
Copy info into empty cells below info, until finds cell with new d Fat Jack Utah Excel Discussion (Misc queries) 3 November 16th 08 08:34 PM
lookup only finds #n/a's Janis Excel Discussion (Misc queries) 4 July 26th 07 11:02 PM
find next finds too much. No Name Excel Programming 5 January 21st 05 08:00 PM
Find finds nothing, and errors Chris M.[_3_] Excel Programming 1 August 25th 03 06:31 PM


All times are GMT +1. The time now is 11:17 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"