Name
querytable
.RefreshStyle[= setting
]
Synopsis
Determines how the query affects surrounding items on the worksheet when the query table is refreshed.
Setting |
Description |
---|---|
xlInsertDeleteCells |
Inserts or deletes new rows and columns created by the query, moving surrounding items up or down and to the right or left as needed (default). |
xlOverwriteCells |
No new rows or columns are added to the worksheet. Surrounding items are overwritten as needed. |
xlInsertEntireRows |
Inserts a new row for each record returned by the query. Shifts existing items down as needed to accommodate the number of records returned. |
The following code modifies an existing query table to insert new rows on the worksheet as needed, shifting existing items on the worksheet down:
Set qt = ActiveSheet.QueryTables(1) qt.RefreshStyle = xlInsertEntireRows qt.Refresh
If a subsequent query reduces the number of records returned, the contents of the query table are replaced, but the rows that were previously shifted down are not shifted back up again as they would be if RefreshStyle
was set to xlInsertDeleteCells
.
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.