Delete all data rows from an Excel table (apart from the first)

后端 未结 9 2140
执笔经年
执笔经年 2020-12-01 09:16

Just recently I\'ve been trying to delete all data rows in a table, apart from the first (which needs to just be cleared)

Some of the tables being actioned could alr

9条回答
  •  既然无缘
    2020-12-01 10:10

    I wanted to keep the formulas in place, which the above code did not do.

    Here's what I've been doing, note that this leaves one empty row in the table.

    Sub DeleteTableRows(ByRef Table As ListObject, KeepFormulas as boolean)
    
    On Error Resume Next
    
    if not KeepFormulas then
        Table.DataBodyRange.clearcontents
    end if
    
    Table.DataBodyRange.Rows.Delete
    
    On Error GoTo 0
    
    End Sub
    

    (PS don't ask me why!)

提交回复
热议问题