+ Reply to Thread
Results 1 to 6 of 6

Thread: Using Mutiple Error Handlers for Same Error Number

  1. #1
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Using Mutiple Error Handlers for Same Error Number

    Hi all in correlation to my previous post, I maybe able to delete my query link
    through few error checks. However,I'm not real sure how to set this up.

    Here's my attempt to handle different existing conditions for the same error. I don't
    think it is stepping through the code for each error handler they way I intended.

    
    Sub Macro2()
    Dim List1 As Label
    Dim List2 As Label
    Dim List3 As Label
    ' Macro2 Macro
    ' Macro recorded 2/11/2010 by BDB
    '
     On Error GoTo errHandler
    '
        Range("A6:C16").Select
        With ActiveSheet
        .QueryTables("IN Stock Status Report - 6896_13.IRP").Delete
    errHandler:
    On Error GoTo List1
     If Err.Number = 9 Then
        .QueryTables("IN Stock Status Report - 6896_12.IRP").Delete
        End If
    List1:
    On Error GoTo List2
    If Err.Number = 9 Then
        .QueryTables("IN Stock Status Report - 6896_12.IRP").Delete
        .QueryTables("IN Stock Status Report - 6896_13.IRP").Delete
        End If
    List2:
    On Error GoTo List3
     If Err.Number = 9 Then
        .QueryTables("IN Stock Status Report - 6896.IRP").Delete
        End If
    List3:
    If Err.Number = 9 Then
    MsgBox Err.Number
    End If
    Exit Sub
    
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$6:$C$16"), , xlYes).Name = _
            "List1"
        Range("A6:C17").Select
        End With
    End Sub
    Any help is appreciated.

    Thanks,

    BDB

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Using Mutipl Error Handlers for Same Error Number

    Why start a new post if it isn't solved? At least post a link to the previous post!
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Using Mutiple Error Handlers for Same Error Number

    Roy, I wanted this thread to be treated as a different problem/issue. This post is focused on dealing with handling multiple error handlers for the same error number (regardless of the error code #). I'm needing to fix this code so if it jumps into an error handler and the set of commands proceeding do not handle the error, then it will step to another error handler and run it's set of commands. I want to setup a chain of different conditions that it can run through until it finds a set of commands that will match the number of conditions that's causing the error.

    I only wanted to reference this to the other post because the code I've put in this post show the same QueryTables that I'm trying to delete.

    If this helps here's a link to my other thread.

    http://www.excelforum.com/excel-prog...-wildcard.html

    Thanks for any help in resolving either problem.

    BDB

  4. #4
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Using Mutiple Error Handlers for Same Error Number

    I've thought maybe something like this would work but I'm getting a

    Compile Error:
    Invalid or unqualified refernence

    for what's highlighted
    Sub Macro2()
    Dim List1 As Label
    
    ' Macro2 Macro
    ' Macro recorded 2/11/2010 by BDB
    '
     On Error GoTo errHandler
    '
        Range("A6:C16").Select
        With ActiveSheet
        .QueryTables("IN Stock Status Report - 6896_12.IRP").Delete
        End With
         If Err.Number = 0 Then
         Exit Sub
         Else
          If Err.Number <> 0 Then
         On Error Resume Next
        .QueryTables("IN Stock Status Report - 6896_13.IRP").Delete
        .QueryTables("IN Stock Status Report - 6896_14.IRP").Delete
        .QueryTables("IN Stock Status Report - 6896.IRP").Delete
         End If
             If Err.Number = 9 Then
             On Error Resume Next
        .QueryTables("IN Stock Status Report - 6896_14.IRP").Delete
        .QueryTables("IN Stock Status Report - 6896.IRP").Delete
         End If
                  If Err.Number = 9 Then
                  On Error Resume Next
        .QueryTables("IN Stock Status Report - 6896.IRP").Delete
         End If
         End If
        Exit Sub
    
    errHandler:
    On Error Resume Next
    BDB

  5. #5
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777

    Re: Using Mutiple Error Handlers for Same Error Number

    I have no idea what you're trying to do, but the proximate problem is that you have an End With statement, and then continuue to make reference to .QueryTables.

    Suggest you get and use SmartIndenter, which make problems like this visually obvious:
    Sub Macro2()
        Dim List1       As Label
    
        ' Macro2 Macro
        ' Macro recorded 2/11/2010 by BDB
        '
        On Error GoTo errHandler
        '
        Range("A6:C16").Select
        With ActiveSheet
            .QueryTables("IN Stock Status Report - 6896_12.IRP").Delete
        End With
        If Err.Number = 0 Then
            Exit Sub
        Else
            If Err.Number <> 0 Then
                On Error Resume Next
                .QueryTables("IN Stock Status Report - 6896_13.IRP").Delete
                .QueryTables("IN Stock Status Report - 6896_14.IRP").Delete
                .QueryTables("IN Stock Status Report - 6896.IRP").Delete
            End If
            If Err.Number = 9 Then
                On Error Resume Next
                .QueryTables("IN Stock Status Report - 6896_14.IRP").Delete
                .QueryTables("IN Stock Status Report - 6896.IRP").Delete
            End If
            If Err.Number = 9 Then
                On Error Resume Next
                .QueryTables("IN Stock Status Report - 6896.IRP").Delete
            End If
        End If
        Exit Sub
    
    errHandler:
        On Error Resume Next
       
    End Sub
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Valued Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    639

    Re: Using Mutiple Error Handlers for Same Error Number

    SHG,

    After my last reply, I diddiscover my missing "End With". Sorry, I wasn't able to update my finding and correction there after.

    What I'm trying to do is build some code which will delete all possible links (ie:.QueryTables("IN Stock Status Report - 6896_*.IRP").

    Each time I update my sheet from it's external sourceI an active querry table link gets placed into the page. The only reason I know this, is because, when I try to build a filter list on the sheet, I get a message that the link has to be removed in order for me to add the list. I found through macro recording my manual removal that the number of links can vary each time.

    Basically what I'm trying to do is check and remove all active querry table links from my worksheet using a loop or error checking method. The code needs to step through
    various scenarios. I don't there are more than 3 or 4 different possible links that need to be removed before a list can be genereated. The inherited problem is if it runs through an
    delete instruction and that link does not exist than the code will error. I need to be able to
    clear that error and have it continue checking and deleting the remaining possible links until all link have been removed.

    HTH's.

    BDB
    Last edited by bdb1974; 02-16-2010 at 10:22 AM.

+ 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.2.0