ABennett757
New Member
- Joined
- Mar 25, 2021
- Messages
- 10
- Office Version
- 365
- 2019
- Platform
- Windows
Hi, I am looking for a way to apply a filter to only leave blank cells in a column and then clear the contents in a different column that are left in the filtered column. The column with my filter criteria corresponds to an item quantity so the idea is to remove all unused items from a default list of about 300 items and then turn the filter off so I am left with a table that only has items with a quantity. I recorded a Macro by completing the filter and column select/clear steps manually and it produced the VBA code below which works as intended. However, this code has the name of the table being filtered ("Table1") hard-coded. I need to copy this worksheet within the same workbook and thus the tables in subsequent copies will have a different name so the Macro no longer works for any copied sheets. So, I'm looking for a way to do this without hard coding the table name (or potentially have the table name as a variable and pull in the name from the active table). Thanks in advance for any replies!
Sub TestFilter()
'
' TestFilter Macro
'
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=6, Criteria1:="="
Range("Table1[ID '#]").Select
Selection.ClearContents
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=6
End Sub
Sub TestFilter()
'
' TestFilter Macro
'
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=6, Criteria1:="="
Range("Table1[ID '#]").Select
Selection.ClearContents
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=6
End Sub