Sanjay Vernekar
New Member
- Joined
- May 28, 2020
- Messages
- 3
- Office Version
- 2016
- Platform
- Windows
Hi all,
I am new to VB scripts . My requirement is to delete all the content of the table (Table structure should remain intact with headers) from all the worksheets in excel.
Each worksheets has multiple tables. Basically we are clearing all the table data so that it can freshly be entered.
I have written the code as below
Sub cleardata()
Dim tbl As ListObject
Dim sht As Worksheet
'Loop through each sheet and table in the workbook
For Each sht In ThisWorkbook.Worksheets
' Ignoring Contents and Cover Page sheet as its contains tables
If sht.Name <> "Contents" And sht.Name <> "Cover Page" Then
For Each tbl In sht.ListObjects
tbl.DataBodyRange.ClearContents
Next tbl
End If
Next sht
End Sub
This code worked in one workbook but not working in another as I am getting a run time error 91. Can you please guide me here.
Thanks in advance,
Sanjay
I am new to VB scripts . My requirement is to delete all the content of the table (Table structure should remain intact with headers) from all the worksheets in excel.
Each worksheets has multiple tables. Basically we are clearing all the table data so that it can freshly be entered.
I have written the code as below
Sub cleardata()
Dim tbl As ListObject
Dim sht As Worksheet
'Loop through each sheet and table in the workbook
For Each sht In ThisWorkbook.Worksheets
' Ignoring Contents and Cover Page sheet as its contains tables
If sht.Name <> "Contents" And sht.Name <> "Cover Page" Then
For Each tbl In sht.ListObjects
tbl.DataBodyRange.ClearContents
Next tbl
End If
Next sht
End Sub
This code worked in one workbook but not working in another as I am getting a run time error 91. Can you please guide me here.
Thanks in advance,
Sanjay