Combine results of two Autofilters

vanwooten

New Member
Joined
Dec 15, 2020
Messages
43
Office Version
  1. 365
Platform
  1. Windows
I want to be able to combine the results of the following autofilters that work perfectly individually:

ActiveSheet.ListObjects("Trades").Range.AutoFilter Field:=20, Criteria1:="=*-*" & Format(Month(Date), "00")
ActiveSheet.ListObjects("Trades").Range.AutoFilter Field:=14, Criteria1:="="

So I would get records from the current month on the first filter on column 20 PLUS records where column 14 is blank.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can simply run those two lines of code one after another. Although, it can be re-written as follows...

VBA Code:
With ActiveSheet.ListObjects("Trades").Range
    .AutoFilter Field:=20, Criteria1:="=*-*" & Format(Month(Date), "00")
    .AutoFilter Field:=14, Criteria1:="="
End With

Hope this helps!
 
Upvote 0
You can simply run those two lines of code one after another. Although, it can be re-written as follows...

VBA Code:
With ActiveSheet.ListObjects("Trades").Range
    .AutoFilter Field:=20, Criteria1:="=*-*" & Format(Month(Date), "00")
    .AutoFilter Field:=14, Criteria1:="="
End With

Hope this helps!
That code runs like an AND. I need an OR.
 
Upvote 0
I need an OR.
Then you could either add another column to the ListObject to mark rows that meet either criteria and then AutoFilter or you could use Advanced Filter.

Here is an Advanced Filter option which assumes nothing in the second column to the right of the ListObject

VBA Code:
Sub Test()
  Dim rCrit As Range
  
  With ActiveSheet.ListObjects("Trades").Range
    Set rCrit = .Offset(, .Columns.Count + 1).Resize(2, 1)
    rCrit.Cells(2).Formula = Replace(Replace("=OR(ISNUMBER(SEARCH(""-*""&TEXT(TODAY(),""mm""),#)),^="""")", "#", .Cells(2, 20).Address(0, 0)), "^", .Cells(2, 14).Address(0, 0))
    .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
    rCrit.Cells(2).ClearContents
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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