+ Reply to Thread
Results 1 to 3 of 3

Error handling in a search

  1. #1
    michaelberrier
    Guest

    Error handling in a search

    I am using a Range(XX).Find search to find a name in a single column,
    and I am trying to build an error handling routine so that different
    actions will execute depending on whether the query is found. The
    trouble is that the error routine executes every time regardless of the
    result of the search.

    Here is the code:

    Sub Look_Here1()
    Dim FoundCell As Range
    Dim WhatFor As Variant
    WhatFor = ActiveSheet.Cells(7, 2).Value

    Set FoundCell = Range("B8:B990").Find(What:=WhatFor,
    after:=ActiveCell, _
    SearchDirection:=xlNext, searchorder:=xlByRows,
    _
    MatchCase:=False)

    FoundCell.Offset(0, -1).Select
    ActiveCell.FormulaR1C1 = "X"
    Selection.Offset(0, 3).Select

    On Error GoTo NotFound

    NotFound:
    Range("a7").Select
    ActiveCell.FormulaR1C1 = "X"
    Range("D7").Select


    End Sub

    Where have I gone wrong?

    Any help will be appreciated.
    mb


  2. #2
    Ardus Petus
    Guest

    Re: Error handling in a search

    If FoundCell is Nothing then
    ...
    else
    ...
    end if

    HTH
    --
    AP

    "michaelberrier" <[email protected]> a écrit dans le message de news:
    [email protected]...
    >I am using a Range(XX).Find search to find a name in a single column,
    > and I am trying to build an error handling routine so that different
    > actions will execute depending on whether the query is found. The
    > trouble is that the error routine executes every time regardless of the
    > result of the search.
    >
    > Here is the code:
    >
    > Sub Look_Here1()
    > Dim FoundCell As Range
    > Dim WhatFor As Variant
    > WhatFor = ActiveSheet.Cells(7, 2).Value
    >
    > Set FoundCell = Range("B8:B990").Find(What:=WhatFor,
    > after:=ActiveCell, _
    > SearchDirection:=xlNext, searchorder:=xlByRows,
    > _
    > MatchCase:=False)
    >
    > FoundCell.Offset(0, -1).Select
    > ActiveCell.FormulaR1C1 = "X"
    > Selection.Offset(0, 3).Select
    >
    > On Error GoTo NotFound
    >
    > NotFound:
    > Range("a7").Select
    > ActiveCell.FormulaR1C1 = "X"
    > Range("D7").Select
    >
    >
    > End Sub
    >
    > Where have I gone wrong?
    >
    > Any help will be appreciated.
    > mb
    >




  3. #3
    michaelberrier
    Guest

    Re: Error handling in a search

    Works perfect. I bet I tried every word in that space except
    "nothing".

    Thanks a bunch.
    mb


+ 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