+ Reply to Thread
Results 1 to 3 of 3

If Cells.Find finds something

  1. #1
    achidsey
    Guest

    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. #2
    Jim Thomlinson
    Guest

    RE: 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. #3
    achidsey
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1