Results 1 to 5 of 5

Thread: Error Handling

  1. #1
    Join Date
    Dec 2005
    Posts
    45

    Unanswered: Error Handling

    I am calculating IRR's within a loop with the code below. If an error occurs when calculating the IRR, I need to assign a value of 0 to the variable and continue on to the next loop. Can anyone suggest a way to do this? Iserror doesn't work, so I need error handling instead.

    for ctr = 1 to 100

    If iserror(irr(varray(), -.09) then
    final = 0
    else
    final = irr(varray(), -.09)
    end if

    debug.print final

    next ctr

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Code:
    On Error Resume Next
    
    ... Do your thing ...
    
    If Err = True Then
    
       ... Do what you do here ...
    
       Err.Clear
    End If
    have fun,
    tc

  3. #3
    Join Date
    Dec 2005
    Posts
    45
    I would expect this to print the word "error", but it doesn't. Is my syntax not correct?

    Sub test()
    On Error Resume Next

    final = 1 / 0

    If Err = True Then
    Debug.Print "error"
    End If

    Err.Clear
    End Sub

    Thanks again!

  4. #4
    Join Date
    Mar 2006
    Posts
    163
    Try just If Err Then.

  5. #5
    Join Date
    Dec 2005
    Posts
    45
    Thanks norie. That worked, as did 'If Err.Number <>0'.

Posting Permissions

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