VBA Clear Table Content

VBA Clear Table Content in Excel

VBA Clear Table Content in Excel. This means clearing or deleting or removing data from the table in Excel using VBA. Here we use the ListObjects collection and ClearContents property to delete or clear data. In this tutorial let us learn the example and step by step instructions to clear content from the table.

Example to VBA Delete Table Content in Excel

Let us see the example to clear content or data from the table of data body range. The sheet name defined as ‘Table‘. And we use table name as ‘MyDynamicTable‘. You can change these two as per your requirement. Where ClearContents property is used to clear data from the table.

'VBA Clear Table Content
Sub VBAF1_Clear_Table_Content()
    
    'Definf Sheet and table name
     With Sheets("Table").ListObjects("MyDynamicTable")
        
        'Check If any data exists in the table
        If Not .DataBodyRange Is Nothing Then
            'Clear Content from the table
            .DataBodyRange.ClearContents
        End If
        
    End With
    
End Sub

Output: Here is the following output screenshot of above example macro code.

VBA Clear Table Content in Excel

Instructions to Use Example Macro Code

You can follow step by step instructions to run above macro example VBA code.

  • Open Visual Basic Editor(VBE) by clicking Alt +F11
  • Go to code window by clicking F7
  • Copy above specified macro or procedure
  • Paste above copied code in code window in the visual basic editor(VBE)
  • Run macro by clicking F5 or Run command
  • The difference between before and after macro, see the output screenshot.

Other Related References

Click on the following links for related reference articles. It helps for your reference.

VBA Tables Tables Examples

Leave a Comment

Your email address will not be published. Required fields are marked *