+ Reply to Thread
Results 1 to 3 of 3

How do I perform a certain function if VBA throws up an error?

  1. #1
    Matt
    Guest

    How do I perform a certain function if VBA throws up an error?


    IF the below code throws up an error (i.e. lookup_value, a parameter
    passed into the sub/function is not contained in the worksheet) THEN
    (do something)...

    ELSE (do something else)....

    END IF

    I'm sure its trivial, any help appreciated.



    Cells.Find(What:=lookup_value, After:=ActiveCell, LookIn:=xlFormulas,
    LookAt _
    :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
    MatchCase:= _
    False, SearchFormat:=False).Activate

    Many thanks

    Matt


  2. #2
    Andrew Taylor
    Guest

    Re: How do I perform a certain function if VBA throws up an error?


    On Error Resume Next ' turns off normal error trapping
    ' your code that may fail here
    If Err.Number then ' Err.Number is error code. 0 = no error
    ' error handling here (Err.Description contains error message)
    End if
    On Error Goto 0 ' reset normal error trapping


    Matt wrote:
    > IF the below code throws up an error (i.e. lookup_value, a parameter
    > passed into the sub/function is not contained in the worksheet) THEN
    > (do something)...
    >
    > ELSE (do something else)....
    >
    > END IF
    >
    > I'm sure its trivial, any help appreciated.
    >
    >
    >
    > Cells.Find(What:=lookup_value, After:=ActiveCell, LookIn:=xlFormulas,
    > LookAt _
    > :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
    > MatchCase:= _
    > False, SearchFormat:=False).Activate
    >
    > Many thanks
    >
    > Matt



  3. #3
    Matt
    Guest

    Re: How do I perform a certain function if VBA throws up an error?

    perfect, knew it would be simple.

    many thanks


+ 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