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

后端 未结 9 2155
执笔经年
执笔经年 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:00

    I have 3 routines which work just fine, just select a cell in a table and run one of the subroutines

    Sub ClearTable()
    If Not ActiveCell.ListObject Is Nothing Then
        ActiveCell.ListObject.DataBodyRange.Rows.ClearContents
    End If
    End Sub
    

    and Shrink Table to remove the databody range except from the headers and the first data row

    Sub ShrinkTable()
    If Not ActiveCell.ListObject Is Nothing Then
        ActiveCell.ListObject.DataBodyRange.Delete
    End If
    End Sub
    

    and Delete Table to completely delete the table from the sheet

    Sub DeleteTable()
    If Not ActiveCell.ListObject Is Nothing Then
        ActiveCell.ListObject.Delete
    End If
    End Sub
    

提交回复
热议问题