VBA & Macro Problems

How to Delete Excel Table Rows in WPS Spreadsheets When a Formula Returns Blank

Jason MillerJason Miller Nov 13, 2026 869 views

Question details

The user needs a VBA macro that deletes Excel table rows when a target cell contains a formula returning an empty string, without triggering Runtime Error 1004.

How to Delete Excel Table Rows in WPS Spreadsheets When a Formula Returns Blank
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
The user is maintaining an Excel table where a column contains formulas that return empty strings and wants to remove rows whose formula result is blank.
Observed behavior
A forward VBA loop deletes rows while iterating, so the range shifts and Excel raises Runtime Error 1004; formula cells returning "" are also not detected as truly blank by IsEmpty.
Before you start

Confirm that the worksheet name, table name, and target column header in the macro match the workbook exactly. Because the cells contain formulas that return empty strings, use Len(cell.Value) = 0 rather than IsEmpty to identify them.

Solution 1Recommended

Loop Through the Table Bottom-Up and Delete Matching ListRows

Use this method to safely remove Excel table rows whose formula result is an empty string while avoiding the range-shift error caused by top-down deletion.

Deleting from the last row upward keeps the remaining row indexes stable, so the loop does not skip rows or reference a removed range.

Testing Len(cell.Value) = 0 catches both zero-length strings and truly empty cells, which is useful when a column contains formulas that return "".

1
Open the VBA editor

In WPS Spreadsheets, open the workbook and press Alt+F11 to open the VBA editor.

2
Insert a module and declare the table objects

Go to Insert > Module, then declare the Workbook, Worksheet, and ListObject variables for the target table.

3
Set the table and target column

Use Set ws = ThisWorkbook.Worksheets("Test") and Set tblTest = ws.ListObjects("Test_T"), then point to tblTest.ListColumns("Child #").DataBodyRange.

4
Loop from the last data row to the first

Write For i = tblTest.ListRows.Count To 1 Step -1 and test If Len(tblTest.ListColumns("Child #").DataBodyRange.Cells(i).Value) = 0 Then.

5
Delete the matching ListRow

Inside the condition, call tblTest.ListRows(i).Delete to remove only the table row.

Runtime Error 1004 avoided: Deleting ListRows from bottom to top prevents the loop range from shifting under the active index, which is the main cause of Runtime Error 1004.

Remove Blank Formula Rows from an Excel Table in WPS Spreadsheets

Run a bottom-up VBA ListRows loop in WPS Spreadsheets to delete only the table rows whose formula returns an empty string, keeping the table structure intact and avoiding Runtime Error 1004.

  1. 1. Open the workbook in WPS Spreadsheets: Launch WPS Office, open the Excel-compatible workbook that contains the table and formulas.
  2. 2. Insert the bottom-up VBA ListRows macro: Press Alt+F11 to open the VBA editor, insert a module, and paste the macro that loops from ListRows.Count To 1 Step -1 and deletes rows where Len(...) = 0.
  3. 3. Run the macro and verify the table: Run the macro and confirm that only rows whose formula returns "" are removed while the Excel table object and data remain intact.
Deletes only table rows where the target formula returns an empty stringSupports Excel-compatible VBA macros, ListObjects, .xlsx and .xlsm workbook formatsKeeps the remaining table data and formulas intact without shifting loop errorsWorks in the free, lightweight WPS Office spreadsheet environment
microsoft office alternative - wps office

Frequently Asked Questions

Why does deleting rows in a forward loop cause Runtime Error 1004?

When you delete a row while looping from top to bottom, the remaining rows shift upward, so the loop can refer to a row that no longer exists or skip rows. Loop from ListRows.Count To 1 Step -1 to keep the index stable.

Should I use IsEmpty to test a formula returning an empty string?

No. IsEmpty returns False for cells that contain a formula, even if the formula result is a zero-length string. Use Len(cell.Value) = 0 instead.

Does tblTest.ListRows(i).Delete remove worksheet rows outside the table?

No. It deletes the table row from the ListObject only, so cells outside the table range are not directly deleted.

How do I run this VBA macro in WPS Spreadsheets?

Open the workbook in WPS Spreadsheets, press Alt+F11 to open the VBA editor, insert the code into a module, and run the macro from the Macro dialog or the VBA editor.