Delete blank rows but one

I have an ODS file with around 31,000 rows. About 5,000 are blank and interspersed with the data rows.

Data
Data
{Empty}
Data
Data
{Empty}
{Empty}
{Empty}
New Data

What I want to do is delete all {Empty} rows except for one to separate the groups.

Data
Data
{Empty}
New Data
New Data
{Empty}
(et cetera)

I tried a macro that would delete blank rows but it didn’t work. Any suggestions?

Add a column to the right with formulas that count the total number of nonblank cells in the current row (to the left of the new column) and the next row (to the left of the new column). In the filter by new column, set the equality criterion to 0. Delete the filtered rows.

1 Like

Could you possibly give a sample?

Assuming Column A represent the state (empty|not empty) for ALL Columns with Data:

def remove_empty_rows_except_one(*_):
    doc = XSCRIPTCONTEXT.getDocument()
    column = doc.Sheets["Sheet1"][:,0]  # adjust to YOUR sheetname
    rows = column.Rows
    empties = [(empty.RangeAddress.StartRow, empty.Rows.Count)
                     for empty in column.queryEmptyCells() ]
    for rowindex, count in reversed(empties[:-1]):
        if count > 1:
            rows.removeByIndex( rowindex, count-1 )

probably you need apso.oxt to manage|organize python-scripts

The condition for “bad” rows is very simple: if there is nothing in the current row and the previous row, then this row is “bad”. You can check it in any way. for example, =LEN(TEXTJOIN("";1;A1:E2))=0. It seems to me that the simpler way is the usual COUNTA(previous row and current row).
In the auxiliary column, put 1 in the first row - regardless of whether this row is filled or empty, it will remain in place. On the second row, write the formula
=IF(COUNTA(A1:E2);ROW();"")
(or COUNTA(A1:A2) or COUNTA(A1:AW2) - I don’t know how many columns are in your table)
Replicate the formula to the end of the table. Sort the table by the values ​​in the auxiliary column - all “bad rows” will move to the end of the table. Delete the auxiliary column.

DelEmptyRows

4 Likes