If we use Power Query to load data into an Excel Table, we may encounter an annoying default setting, whereby Table columns resize every time we refresh the query.
It isn’t a problem if this is just data used for other calculations. However, if the query is part of your reporting, it may not display correctly in your reports.
In this post, we will look at how to fix this problem.
Watch the video
Manually change the Table Properties
Thankfully, there is an easy way to stop this from happening.
- Select a cell within the Table.
- Click Table Design > Properties
- The External Data Properties window opens
There are lots of useful options in here, so let’s just look at them briefly:
- Include row numbers: Will add a _RowNum column to the start of the Table. From a power query perspective, this is not particularly useful. If we wanted a row number, we could add this as an Index column before loading the query into the Excel Table.
- Adjust column width: For our scenario, this option is causing the problem. Uncheck that option, and the columns will no longer resize.
- Preserve column sort/filter/layout: This allows us to retain the sort, filter, or layout options that existed prior to clicking refresh. If we want a clean start each time we load, we should uncheck this box.
- Preserve cell formatting: If you have cell formatting applied, this will be retained based on the position of the cells. So, for example, if you highlighted the 2nd row, the 2nd row will still be highlighted after refreshing the query. The exception is if the formatting is below the length of the refreshed query; at this point, the formatting is lost going forwards. Uncheck this box if you always want formatting removed.
- If the number of rows in the data range changes upon refresh: There are 3 options in this section. For Power Query, I don’t believe it makes any difference which option is selected. Therefore, I always leave it on the first selection by default.
Once you’ve made your selections, click OK to close the External Data Properties dialog box.
Ta-dah!!! Now, each time we refresh the query, the Table column widths should not resize.
Macro to change all Tables in the Active Workbook
If you have a lot of Tables, it might take you a bit of time. So I have created the following VBA Macro to change all the Tables in the ActiveWorkbook.
Sub StopTableColumnsResize() Dim ws As Worksheet Dim tbl As ListObject Dim qryTbl As QueryTable 'Loop through all worksheets in active workbook For Each ws In ActiveWorkbook.Worksheets 'Loop through all Tables in the worksheet For Each tbl In ws.ListObjects 'Check if the Table is a Query Table Set qryTbl = Nothing On Error Resume Next Set qryTbl = tbl.QueryTable On Error GoTo 0 'If the Table is a Query Table then change settings If Not (qryTbl Is Nothing) Then 'Change the settings qryTbl.AdjustColumnWidth = False 'Alternative options you may want to apply 'qryTbl.RowNumbers = True 'qryTbl.PreserveFormatting = True 'qryTbl.PreserveColumnInfo = True End If Next tbl Next ws End Sub
Whether you have applied the manual method or used the VBA Macro, you never need to have Table columns resizing ever again.
Discover how you can automate your work with our Excel courses and tools.
The complete program for saving time by automating Excel.
Excel Automation Secrets
Discover the 7-step framework for automating Excel.
Office Scripts: Automate Excel Everywhere
Start using Office Scripts and Power Automate to automate Excel in new ways.