question

Sanjay-0385 avatar image
Sanjay-0385 asked ·

Help needed to resolve Object variable or With block variable not set

I am writing a VB script to clear all table data from all the sheets in excel workbook. Each sheet has multiple table .
Below is the code written but getting Object variable or With block variable not runtime error .

Sub cleardata()

Dim tbl As ListObject
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets

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

not-supported
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DSPatrick avatar image
DSPatrick answered ·

Scripting is not supported here on QnA. I'd try asking for help in dedicated forums here.

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG


--please don't forget to Accept as answer if the reply is helpful--


Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management


Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.




Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.