Clear excel table based on number of rows

Jijoy Thomas Poulose 21 Reputation points
2022-09-13T16:56:39.407+00:00

Hello,
I am trying to clear contents of the table(A) if there is less than 2 rows present in the table.

With sheets("Doc").ListObjects("A")
if A.Range.Count <2 then
A.DatabodyRange.ClearContents

0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118.2K Reputation points
    2022-09-14T19:47:13.123+00:00

    Try something like this:

    Dim ws As Worksheet  
    Set ws = Sheets("Doc")  
    Dim t As ListObject  
    Set t = ws.ListObjects("A")  
          
    If t.DataBodyRange.Rows.Count < 2 Then  
       t.DataBodyRange.ClearContents  
    End If  
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.