Filter and hide multiple tables with vba

wbstadeli

Board Regular
Joined
Mar 11, 2016
Messages
151
Office Version
  1. 365
Platform
  1. Windows
Hi,

Im trying to filter multiple tables by a common table header cell called "Match:". If the row in any table on the worksheet in column "Match:" is True, then show that row with the table that it is in, otherwise i want the entire table hidden including the first row right above the table. I have pieced together some code that works pretty good, except the looping (going to next table) seems to not be working properly. It hides all the tables properly until it finds a table that has "True" in the "Match:" column, then this code doesnt continue on to any tables that are below this one. Can anyone help out to see what i need to put in this code so that it continues on to the next table after it hides/or doesn't hide them depending on the value in the "Match:" field? See current code below:
Code:
Sub FilterAllTables()


    Cells.EntireRow.Hidden = False
    
    Dim Tbl As ListObject, Fld As Integer, tCount As Integer, tRng As Range
    For Each Tbl In ActiveSheet.ListObjects
        
        Fld = WorksheetFunction.Match("Match:", Tbl.HeaderRowRange, 0)
            Tbl.AutoFilter.ShowAllData
            Tbl.Range.AutoFilter Field:=Fld, Criteria1:="TRUE"


        On Error Resume Next
        Set tRng = Tbl.HeaderRowRange.Offset(-1).Resize(2)
        tCount = Tbl.DataBodyRange.SpecialCells(xlCellTypeVisible).Count
        If tCount = 0 Then tRng.EntireRow.Hidden = True
        If tCount > 0 Then tRng.EntireRow.Hidden = False
    Next Tbl
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,213,565
Messages
6,114,338
Members
448,569
Latest member
Honeymonster123

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