Autofiler for或VBA条件

我使用Excel表格中的.Autofilter过滤数据,如下所示

if bProds = True then .AutoFilter 4,"<>*strip*",2,"<>*Strip*" .AutoFilter 8,"Product",2,"product" else .AutoFilter 8, "<>Product", 1, "<>product" .AutoFilter 4,"*strip*",2,"*Strip*" end if 

结果集是自动筛选条件满足的行。 在else部分,我想做一个条件,使得结果是不包含第8列中的产品/产品的行,或者包含第4列中的strip / Strip。

由于自动filter返回,如果两个条件都满足,上述代码不起作用。 任何方式使它像我的要求工作?

testing数据也可以从这个drive.google.com链接

第1页:

  Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 --------- ---- ---- ----- ----- ---- ---- ----- 1/07/2015 3 3 Word1 word2 AB Hello Product 1/13/2015 2 1 word2 word1 AB hello product 1/13/2015 2 1 COzier USA Bill Allice Assembly 1/14/2015 3 4 TOny USA Bill Allice Wrox 1/20/2015 2 1 Shawn USA gerard amy Product 1/23/2015 2 1 Wilcox Sanzer Francis Bob Assembly 1/26/2015 3 5 Justin Langer Go febrand Citrix 

第2页:

  Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 --------- ---- ---- ----- ----- ---- ---- ----- 1/20/2015 2 1 Shawn USA gerard amy Product 

表3:

  Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 --------- ---- ---- ----- ----- ---- ---- ----- 1/07/2015 3 3 Word1 word2 AB Hello Product 1/13/2015 2 1 word2 word1 AB hello product 1/13/2015 2 1 COzier USA Bill Allice Assembly 1/14/2015 3 4 TOny USA Bill Allice Wrox 1/23/2015 2 1 Wilcox Sanzer Francis Bob Assembly 1/26/2015 3 5 Justin Langer Go febrand Citrix 

 Public Sub autoFilter1() 'Column 8 = "Product" Dim ws As Worksheet Set ws = Worksheets("Sheet1") ws.UsedRange.Rows.EntireRow.Hidden = False If Not ws.AutoFilter Is Nothing Then ws.ShowAllData ws.UsedRange.AutoFilter 8, "product" End Sub Public Sub autoFilter2() 'Column 8 <> "Product" OR Column 4 = "Word1" Dim ws As Worksheet, vRng As Range Application.ScreenUpdating = False Set ws = Worksheets("Sheet1") ws.UsedRange.Rows.EntireRow.Hidden = False If Not ws.AutoFilter Is Nothing Then ws.ShowAllData ws.UsedRange.AutoFilter 8, "<>product" Set vRng = ws.UsedRange.SpecialCells(xlCellTypeVisible) ws.ShowAllData ws.UsedRange.AutoFilter 4, "word1" Set vRng = Union(vRng, ws.UsedRange.SpecialCells(xlCellTypeVisible)) ws.UsedRange.AutoFilter ws.UsedRange.Rows.EntireRow.Hidden = True vRng.Rows.EntireRow.Hidden = False Application.ScreenUpdating = True ws.Cells(1).Select End Sub 

multiAutoFilter