Results 1 to 10 of 10

Error Handling in a Loop

Threaded View

  1. #1
    Registered User
    Join Date
    10-06-2009
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    23

    Error Handling in a Loop

    Dear Gurus,

    I recently encountered this issue when writing an error handling section inside a For loop (VBA for Excel). It seems that the On Error status resets to GoTo 0 after the first time an error has been handled.

    To illustrate this, in the following situation, I expected 5 Message Boxes but I only get 1. After the error handler activates the next loop, the On Error GoTo NextFor seems to have lost its meaning. My purpose is to have a "On Error GoTo Next Loop" mechanism in place. Could you please help?

    Sub test()
    
    For i = 1 To 5
        On Error GoTo NextFor
        Worksheets("NoSuchWorksheet").Activate
    
    NextFor:
        MsgBox "At i = " & i & ", Loop Jumped to NextFor"
        Next
    End Sub
    Last edited by amdk8800; 09-22-2010 at 07:28 PM. Reason: Problem solved

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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