Forum

Autofilter by crite...
 
Notifications
Clear all

Autofilter by criteria but if filter criteria blank ignore and not delete cell

2 Posts
2 Users
0 Reactions
242 Views
(@meththini)
Posts: 1
New Member
Topic starter
 

Hi - I am trying to autofilter a field and delete the rows based on the filter, but if one of the criteria in my autofilter brings no data, i want to ignore and move on to the next filter criteria. Currently, my macro stops. Please help!

Sheets("Inventory Status").Activate
Application.DisplayAlerts = True
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
"=*crate*", Operator:=xlOr, Criteria2:="=*probe case*"
ActiveSheet.ListObjects("Table1").DataBodyRange.Delete
ActiveSheet.ShowAllData
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:= _
"=*rep*", Operator:=xlOr, Criteria2:="=*con*"
ActiveSheet.ListObjects("Table1").DataBodyRange.Delete
ActiveSheet.ShowAllData

 

Regards,

Meththini

 
Posted : 29/06/2016 12:58 pm
(@catalinb)
Posts: 1937
Member Admin
 

What do you mean by "my macro stops"? Any macro should stop sometime...

You can check if the table has more than 1 visible cell:

VisibleCellsCount=ActiveSheet.ListObjects(“Table1”).Range.Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count

If VisibleCellsCount>1 Then...

Catalin

 
Posted : 30/06/2016 12:28 am
Share: