Name

querytable.Delete

Synopsis

Deletes a query table. If the query table is refreshing asynchronously, Delete causes an error. Deleting a query table does not remove data from cells on a worksheet—it just removes the ability to refresh those cells from their data source.

The following code deletes all of the query tables on the active worksheet and clears their data:

Dim qt As QueryTable
For Each qt In ActiveSheet.QueryTables
    If qt.Refreshing Then qt.CancelRefresh
    qt.Delete
Next
ActiveSheet.UsedRange.Clear

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.