Convert an Exported Excel Range to a Table Using Access VBA
Question details
Convert fields exported from Access into an Excel table with sortable and filterable headings.

- Product
- Microsoft Access and Microsoft Excel
- Device & OS
- not provided
- Scenario
- Access VBA exports selected fields into specific cells in a new Excel workbook.
- Observed behavior
- The exported cells form a range that still needs to be converted into an Excel table.
Check that the first row of the exported range contains column headings and that you know the final exported row. The example assumes the data is in columns A through C and that your Access VBA code already has a worksheet object named ws.
Create an Excel ListObject after exporting the data
Use this method to convert the exported range into an Excel table as part of the Access VBA export routine.
An Excel ListObject turns the range into a table, providing filter and sort controls in its header row. The example uses numeric values for Excel constants, so it can also be used with late-bound Excel objects.
In Access, press Alt+F11 to open the VBA editor, then open the module or form code that creates the Excel workbook and writes the exported fields.
After the export finishes, set lastRow to the final row written by your routine. Adjust A1:C in the following code if your exported headings or columns occupy a different range.
Add this code after writing the data, using your existing worksheet object and lastRow value: Dim tbl As Object Set tbl = ws.ListObjects.Add(1, ws.Range("A1:C" & lastRow), , 1) tbl.Name = "ExportedData" The first 1 specifies a range source; the second indicates that the first row contains headings. Choose a table name that is unique in the workbook.
Save the workbook in your export routine, then open it in Excel and check that the table covers all exported rows and displays filter arrows in the headings.

Review and filter exported spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Excel format compatibility, making it easy to open and work with exported files. The Access-to-Excel VBA automation itself requires Microsoft Office and is not fixed by WPS.

Frequently Asked Questions
Why should the table be created after the export?
Creating the ListObject after writing the data lets you specify a range that includes the headings and all exported records.
How do I include more than three exported columns?
Change ws.Range("A1:C" & lastRow) to match the full exported range. For example, use ws.Range("A1:E" & lastRow) for columns A through E.
What does the last 1 in ListObjects.Add mean?
It specifies that the first row of the supplied range contains column headings, equivalent to Excel's xlYes constant.
Can I choose a different table name?
Yes. Change tbl.Name = "ExportedData" to a valid Excel table name that is not already used in the workbook.




