Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: On Error code in VBA

  1. #1
    Board Regular
    Join Date
    Jun 2002
    Location
    Lawrence, KS
    Posts
    128
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have two 'Cells.Find()' funtions in my macro before each of the functions I have an
    'On Error GoTo ' statement. they each go to a different line number

    for some reason, if there is an error in the first Cells.Find () [the search value is not there] then the macro will not recognize the second On Error GoTo and it just gives me a run-time error

    is this normal? how can I get around it?

  2. #2
    Board Regular
    Join Date
    Jun 2002
    Location
    Lawrence, KS
    Posts
    128
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    to clarify, it only gives a run-time error in the second one if the search value is not there.

    let me know if you need more details, or want to see code

  3. #3
    MrExcel MVP
    Join Date
    Jun 2002
    Location
    North Canton, OH USA
    Posts
    791
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    This might help... from the help text:

    Error-handling routines rely on the value in the Number property of the Err object to determine the cause of the error. The error-handling routine should test or save relevant property values in the Err object before any other error can occur or before a procedure that might cause an error is called. The property values in the Err object reflect only the most recent error. The error message associated with Err.Number is contained in Err.Description.

    Also:

    Note that Err.Clear is used to clear the Err object's properties after the error is handled.

    'Check for likely Automation errors.
    If Err.Number = 440 Or Err.Number = 432 Then
    ' Tell user what happened. Then clear the Err object.
    Msg = "There was an error attempting to open the Automation object!"
    MsgBox Msg, , "Deferred Error Test"
    Err.Clear ' Clear Err object fields
    End If

    Jim

    Excel 2000; Windows 2000

  4. #4
    Board Regular
    Join Date
    Jun 2002
    Location
    Lawrence, KS
    Posts
    128
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I tried the Err.Clear and that did not help.

    it is a Run-Time error '91'
    Object variable or With block variable not set.


  5. #5
    Board Regular
    Join Date
    Jul 2002
    Location
    San Francisco
    Posts
    88
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is the problem that the Cells.Find() function works (but is not the info you wanted), then the Cells.FindNext() fails?

  6. #6
    Board Regular
    Join Date
    Jun 2002
    Location
    Lawrence, KS
    Posts
    128
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    they are both Cells.find() functions, but they are looking for different pieces of information

  7. #7
    Board Regular
    Join Date
    Jul 2002
    Location
    San Francisco
    Posts
    88
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Can we see the code?

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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