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.
Any help is appreciated.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
Thanks,
BDB
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)
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
I've thought maybe something like this would work but I'm getting a
Compile Error:
Invalid or unqualified refernence
for what's highlighted
BDBSub 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
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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks