VBA Autofilter to filter using 2 columns

mecerrato

Board Regular
Joined
Oct 5, 2015
Messages
174
Office Version
  1. 365
Platform
  1. Windows
I have 2 columns that I would like to filter by but need the results to show for both criteria.

VBA Code:
ActiveSheet.Range("$a$10:$cp$500").AutoFilter Field:=19, Criteria1:="Red"
ActiveSheet.Range("$a$10:$cp$500").AutoFilter Field:=89, Criteria1:="Red"

So if either column S (filed #19) or column CK (filed #89) are equal to Red I want to see them

Anyone know how to solve?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You could create a helper column in col CQ with this formula
Excel Formula:
=OR(S11="Red",CK11="Red")
filled down & then filter that column for TRUE.
 
Upvote 0
Or use an advanced filter …​
I don't want to use a helper column, this is what I have but it only gives me no results, is there such thing as an OR operator I can use?

VBA Code:
Sub Filter_by_Red_CD_LE()
ActiveSheet.Unprotect
Dim ddate As String
ddate = Month(Date)
Dim r As Range

Set r = ActiveSheet.Range("$a$10:$cp$500")
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
  ActiveSheet.ShowAllData
End If
    Selection.AutoFilter
    ActiveSheet.Range("$a$10:$cp$500").AutoFilter Field:=19, Criteria1:="Red"
    ActiveSheet.Range("$a$10:$cp$500").AutoFilter Field:=89, Criteria1:="Red"
    Range(Cells(r.Rows.Count + 1, 1), Cells(Rows.Count, Columns.Count)).EntireRow.Hidden = True
    Range("$a$10:$cp$500").Sort Key1:=Range("B10"), Order1:=xlAscending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    ActiveWindow.ScrollColumn = 47
    ActiveWindow.ScrollRow = 11
Range("A8").Value = "Current Filter = REd LE/CD"
Worksheets("Pipeline").Shapes("Drop Down 11").ControlFormat.Value = 0

End Sub
 
Upvote 0
Not need any helper column and the advanced filter is an easy way …​
 
Upvote 0
As it may depend on how smart is the worksheet design I need at least an attachment …​
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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