Delete a query table

wut

Banned
Joined
Dec 13, 2010
Messages
229
Code:
Dim Q as QueryTable
 
For Each Q in ActiveSheet.QueryTables
   Q.Delete
Next

This code does not delete query table objects from the sheet. I know it's not working because I'm using a macro to delete old tables, and create new ones in their place with the same name.

Whenever the macro creates a new table, the new table's name looks like this: "Name_#", because the old tables are being plastered over with the new info.

I can also zoom out to 10% after running the code and see the old table, still present.

Is there another way to get rid of a querytable without just deleting the entire sheet?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I've never seen this behavior before so this is just a guess:

Goto the "Names" dialog box and see if the query is still listed. If so delete it via the "Names" dialog. If that solves the problem then delete the name in your code.

Hope it works.

Gary
 
Upvote 0
Yeah, everwhere I look, they say I should be seeing the opposite behavior; the contents should persist, but the query table should vanish. It's making me wonder if there's something wrong with the code that I'm using to create the tables in the first place. I'll have to look into that some other time (library's closing).

Your idea worked perfectly. I never would have come up with it on my own.

Thanks, I really appreciate it. :biggrin:
 
Upvote 0
Are you using 2007 or 2010? These have a different syntax to get at the query tables. Something about ListObjects (I've forgotten at the moment but you should be able to google it).

ξ
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top