I wish to reset a table (listObject) via VBA. I tried it in two ways:
Idea 1: Clear table content and resize the table to one column
With ActiveWorkbook.Worksheets("Sheet1").ListObjects("tblExample")
If Not .DataBodyRange Is Nothing Then .DataBodyRange.ClearContents
Dim numColumns As Long: numColumns = .ListColumns.Count
If numColumns > 1 Then
.DataBodyRange.Offset(1).Resize(, .Columns.Count - 1).Delete 'Last statement
End If
End With
The problem: When evaluating the last statement I get the runtime '438' error stating something like: 'Object does not support this Property or Method.'
Idea 2: Delete the table and make a new one
With ActiveWorkbook.Worksheets("Sheet1")
If .ListObjects.Count = 1 Then
.ListObjects(1).Delete
.ListObjects.Add(Destination:=.Range("I1:I105")).Name = "tblExample"
End If
End With
The problem: The new table is placed at a random location (= selected cell).