Hi,
I would like to be able to loop though all tables in a workbook, apply a filter and then delete the visible cells.
I have the following code which filters all of the tables:
However the delete visible cells element only works on the first table and then throws up a run-time 1004 error - Delete method of Range class failed for all of the other tables.
Many thanks in advance.
I would like to be able to loop though all tables in a workbook, apply a filter and then delete the visible cells.
I have the following code which filters all of the tables:
VBA Code:
Sub Filter_Data()
Dim sht As Worksheet
Dim lstobj As ListObject
Dim Port_Name As String
Port_Name = ThisWorkbook.Sheets("Home").Range("A1").Value
For Each sht In ThisWorkbook.Worksheets
For Each lstobj In sht.ListObjects
With lstobj
.AutoFilter.ShowAllData
.DataBodyRange.AutoFilter Field:=1, Criteria1:="<>" & Port_Name
.DataBodyRange.SpecialCells(xlCellTypeVisible).EntireRow.delete
.AutoFilter.ShowAllData
End With
Next lstobj
Next sht
End Sub
However the delete visible cells element only works on the first table and then throws up a run-time 1004 error - Delete method of Range class failed for all of the other tables.
Many thanks in advance.