Loop Through Tables In The Workbook Or Active Sheet

less than 1 minute read

Loop through all tables in the workbook

Sub LoopThroughAllTablesinWorkbook()
  Dim tbl As ListObject
  Dim sht As Worksheet

  '// Loop through each sheet and table in the workbook
  For Each sht In ThisWorkbook.Worksheets
  For Each tbl In sht.ListObjects

  'Do something to all the tables...
  tbl.ShowTotals = True

  Next tbl
  Next sht

End Sub

Loop through all tables in the active sheet

Sub LoopThroughAllTablesInWorksheet()

  Dim tbl As ListObject

  '// Loop through each sheet and table in the workbook
  For Each tbl In ActiveSheet.ListObjects

  '// Do something to all the tables...
  tbl.ShowTotals = True
    
  Next tbl

End Sub

Tags:

Categories:

Updated: