Excel 2019
I am having an issue whereby Excel will not allow me to convert a range to a table and provides the "Run-time error '1004': A Table cannot overlap a range that contains a PivotTable report, query results, protected cells or another table caused by code line "Set tbl = ws.ListObjects.Add(xlSrcRange, selectedRange, , xlYes)"
Quick background.
I have VBA that imports a delimited text file.
The imported data is presented vertically my VBA selects it as a range which is then passed to a Power Query to remove unwanted lines of data and pivot the data horizontally.
On previous use this all worked fine until today for some reason Excel now gives the above error.
Nothing in the code was changed and I have been using the same test delimited text file so I have no clue what is going on.
I have written some code that is meant to clear all connections, tables and querys before the text file is imported which is below but the error still happens.
As the below images show, there are no connections, querys or tables in the workbook.
The wierd thing is that once I have ran the remove connections Sub and close and reopen the workbook my VBA to change the selected rang to Table works.
I really do not want to have to close and reopen the workbook each time I wish to create a new table.
If anyone can throw some light on this I would be very grateful as I am stumped.
This sub removes any data connections, querys and so on once the text file has been imported.
This code selects the range from the imported delimited text file.![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Excel error msg.jpg![]()
Please Login or Register to view this content.
Connections.jpg
Querys.jpg
Bookmarks