Deselect an Excel Table DataBodyRange After VBA Sorting
Question details
Replace the selected table body with a single-cell selection after sorting an Excel table with VBA.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA macro sorts a ListObject and the user wants to clear the DataBodyRange selection afterward.
- Observed behavior
- Activating another worksheet cell does not remove the table body selection.
Identify the table your macro sorts and make sure its worksheet is active when the selection code runs. The table must contain at least one data row for DataBodyRange to exist.
Select the First Table Body Cell After Sorting
Use this approach to replace the selected DataBodyRange with a single-cell selection after the sort.
Open the VBA editor from Excel's Developer tab and locate the macro that sorts the table.
Immediately after the sort code, add: Dim obj As ListObject Set obj = ActiveSheet.ListObjects(1) If Not obj.DataBodyRange Is Nothing Then obj.DataBodyRange.Cells(1, 1).Select
Replace ListObjects(1) with ListObjects("TableName") if the sorted table is not the first table on the active sheet. Use the table's actual name.
Return to Excel and run the macro from Developer > Macros. After sorting, the first data cell should be selected instead of the full table body.

Work With Excel Tables in WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel workbooks. It can help you migrate everyday spreadsheet work, but it does not fix Excel's VBA selection behavior; macro support may vary by version.

Frequently Asked Questions
Does selecting the first table cell completely remove the selection?
No. DataBodyRange.Cells(1, 1).Select replaces the table body selection with a selection of its first data cell.
What happens if the Excel table has no data rows?
DataBodyRange is Nothing when the table has no data rows. Use an If Not obj.DataBodyRange Is Nothing check before selecting a cell.
How do I target a specific table in the macro?
Replace ActiveSheet.ListObjects(1) with ActiveSheet.ListObjects("TableName"), using the actual table name. Ensure that the table's worksheet is active before calling Select.
Why use Select instead of activating another cell?
Select explicitly changes the selection to the specified cell. Activating a cell may change the active cell without replacing the existing multi-cell selection.




