VBA & Macro Problems

Delete Completely Empty Rows from Excel Tables with VBA in WPS Office

Ayan MasoodAyan Masood Nov 13, 2026 869 views

Question details

The user needs a VBA macro that checks every named Excel table and deletes only rows where all cells in the data row are completely empty.

Delete Completely Empty Rows from Excel Tables with VBA in WPS Office
Product
WPS Office Excel
Device & OS
not provided
Scenario
A workbook contains named Excel tables with blank data rows, and the user wants to clean them with VBA instead of deleting rows manually.
Observed behavior
The macro should evaluate the complete table row, not only a single column, so partially filled rows are preserved and only fully empty rows are removed.
Before you start

Open the workbook that contains the named tables and confirm the target worksheet name in the VBA code matches your sheet. The macro only processes table data rows, so header rows and total rows are not affected.

Solution 1Recommended

Delete completely empty rows from all Excel tables by looping backward with VBA

Use this method when you want one macro to process every named table on a worksheet and delete only rows whose entire table range is empty.

The macro uses Application.CountA on each ListRow range. If CountA returns 0, no cell in that row contains a value, formula result, text, or error, so the row is safe to delete.

Looping from the last data row to the first prevents Excel from skipping rows after a deletion because deleting a row shifts lower rows upward but does not affect the already processed rows above.

1
Open the VBA editor

In WPS Office Excel, go to the Developer tab and click Visual Basic, or press Alt+F11 to open the Microsoft Visual Basic for Applications editor.

2
Insert a module

In the editor, click Insert > Module to create a new standard module where you can paste the macro.

3
Paste the macro code

Paste the following macro: Sub DeleteEmptyRowsForAllTables() Dim ws As Worksheet, tbl As ListObject, i As Long Set ws = ThisWorkbook.Worksheets("Sheet1") For Each tbl In ws.ListObjects If Not tbl.DataBodyRange Is Nothing Then For i = tbl.ListRows.Count To 1 Step -1 If Application.CountA(tbl.ListRows(i).Range) = 0 Then tbl.ListRows(i).Delete Next i End If Next tbl End Sub

4
Run the macro

Place the cursor inside the macro and press F5, or click Run > Run Sub/UserForm. Confirm that the active workbook contains the named tables you want to clean.

Delete completely empty rows from all Excel tables by looping backward with VBA
Empty table rows removed: After the macro runs, only rows where every cell in the table data row was empty are deleted. Partially filled rows remain unchanged.

Delete completely empty Excel table rows with a VBA macro in WPS Office

WPS Office Spreadsheets includes VBA tools that can run the same ListObjects loop as Excel. Open the Visual Basic Editor, insert a module, paste the macro, and run it to remove all fully empty rows from named tables in one pass.

  1. 1. Open the workbook in WPS Office: Launch WPS Office Spreadsheets and open the workbook that contains the named Excel tables.
  2. 2. Open the Visual Basic Editor: Go to the Developer tab and click Visual Basic, or press Alt+F11. If the Developer tab is not visible, enable it from File > Options > Customize Ribbon.
  3. 3. Insert a module and paste the VBA code: Click Insert > Module and paste the macro that loops through tbl.ListRows from bottom to top and uses Application.CountA(tbl.ListRows(i).Range) = 0.
  4. 4. Run the macro: Press F5 with the cursor inside the macro, or click Run > Run Sub/UserForm, and verify that the target worksheet is selected.
Deletes only fully empty table rows by checking the complete ListRow rangeProcesses rows backward to avoid skipping rows after deletionWorks with Excel-compatible workbooks such as .xlsx and .xlsmFree, lightweight Office suite with a familiar VBA editorEasy to use for workbook cleanup without manual row removal
microsoft office alternative - wps office

Frequently Asked Questions

Why should the macro loop from bottom to top when deleting table rows?

Deleting from the last row upward keeps the indexes of earlier rows stable, so the macro does not skip rows after each deletion.

Does this VBA macro delete the header row or the totals row?

No. The macro only iterates through tbl.ListRows, which represents the data body range, so the header row and total row are not included.

Will a row with formulas that return blank-looking values be deleted?

No. Application.CountA counts cells that contain formulas, even if they display an empty string, so those rows are not considered completely empty.

How can I run this macro on all worksheets instead of only Sheet1?

Add an outer loop such as For Each ws In ThisWorkbook.Worksheets and then iterate ws.ListObjects inside that loop. Make sure each sheet is processed by the same backward row loop.

Do I need to save the workbook in a macro-enabled format?

Yes. To keep the VBA code, save the file in a macro-enabled format such as .xlsm or the WPS-compatible macro-enabled format; saving as a regular .xlsx file may remove the macro.