Loop through all Excel tables in workbook

Raddle

New Member
Joined
Oct 24, 2023
Messages
37
Office Version
  1. 2016
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
 
OK so I am now going for gold ...

Populating the tables with the test data what is best to pick a table row 1 col 1 and start pasting in values?

Inside the new excellent loop, hopefully I can call a new routine (below) to paste that data in

Sub Acnts_Inputdata()

ActiveCell.FormulaR1C1.Select
ActiveCell.FormulaR1C1 = "Test Data"
Selection.AutoFill Destination:=Range("OverReceipting[Employee Name]")
Range("OverReceipting[Employee Name]").Select



End Sub
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top