Hi - trying to delete a bunch of test data from several tables in Excel.
I need to loop through each table and run the delete body content routine, which does work, but only if I manually select a cell in the table first ... so good but not ideal.
I tried this but I am not able to actually select the each table. This will work for only one table if I personally select a cell within that table.
If I select a cell outside of both table ranges, then neither table is cleared.
So I think the challenge remains, 'how does one select a cell in a table in' and then put that in a loop ... so grateful if anyone can help
Sub ForEachTables()
Dim tbl As ListObject
Dim contents As Variant
For Each tbl In ActiveSheet.ListObjects
Clearcontents
Next tbl
End Sub
Sub Clearcontents()
If Not ActiveCell.ListObject Is Nothing Then
ActiveCell.ListObject.DataBodyRange.Rows.Clearcont ents
End If
End Sub
I need to loop through each table and run the delete body content routine, which does work, but only if I manually select a cell in the table first ... so good but not ideal.
I tried this but I am not able to actually select the each table. This will work for only one table if I personally select a cell within that table.
If I select a cell outside of both table ranges, then neither table is cleared.
So I think the challenge remains, 'how does one select a cell in a table in' and then put that in a loop ... so grateful if anyone can help
Sub ForEachTables()
Dim tbl As ListObject
Dim contents As Variant
For Each tbl In ActiveSheet.ListObjects
Clearcontents
Next tbl
End Sub
Sub Clearcontents()
If Not ActiveCell.ListObject Is Nothing Then
ActiveCell.ListObject.DataBodyRange.Rows.Clearcont ents
End If
End Sub