VBA Autofilter Criteria

Gliffix101

Board Regular
Joined
Apr 1, 2014
Messages
81
Hi All,

I currently have code that runs and autofilters a field (31) based on the value of "Cancelled", "Initiated", "Outstanding", "Requested", or "Blank".

I'd like to add a logic test that filters the criteria of "Cancelled", "Initiated", "Outstanding", "Requested if Column 32 > 20 days from today", or "Blank".

Any ideas?

Full code below:

Code:
Sub A_Review()
Dim LastRow As Long
Dim Rng As Range, str1 As String, str2 As String, strx As String, str3 As String, str4 As String, str5 As String
Dim i As Long, wsName As String, temp As String
Dim arrResults
Dim b As Long


Application.ScreenUpdating = False


With Sheets("Combined")
    LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
    Set Rng = .Range("A1:EV" & LastRow)
End With


With Sheets("Search Form")
    str1 = .Range("E8").Text
    str2 = .Range("E12").Text
    str3 = .Range("E16").Text
    str4 = .Range("E20").Text
    str5 = .Range("L12").Text
End With


Sheets.Add After:=Sheets("Search Form")
ActiveSheet.Name = ("Results")
Sheets("Combined").Select
ActiveSheet.AutoFilterMode = False
Rng.AutoFilter Field:=31, Criteria1:=Array("Cancelled", "Initiated", "Outstanding", "Requested", ""), Operator:=xlFilterValues


If y > 0 Then Rng.AutoFilter Field:=16, Criteria1:=(arrResults), Operator:=xlFilterValues
    If Not str1 = "" Then Rng.AutoFilter Field:=4, Criteria1:=str1
    If Not str2 = "" Then Rng.AutoFilter Field:=5, Criteria1:=str2
    If Not str3 = "" Then Rng.AutoFilter Field:=151, Criteria1:=str3
    If Not str4 = "" Then Rng.AutoFilter Field:=152, Criteria1:=str4
    
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Results").Range("A1")


Application.CutCopyMode = False
Selection.AutoFilter
Sheets("Results").Activate
ActiveSheet.Columns.AutoFit


Rows("1:1").Select
    Selection.Find(What:="Current Comment", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.EntireColumn.Select
    Selection.ColumnWidth = 40


Sheets("Results").Activate
Columns("AM:ET").Delete


Sheets("Results").Activate
wsName = Format(Date, "mmddyy")
If WorksheetExists(wsName) Then
    temp = Left(wsName, 6)
    i = 1
    wsName = temp & "_" & i
    Do While WorksheetExists(wsName)
        i = i + 1
        wsName = temp & "_" & i
    Loop
End If


ActiveSheet.Name = wsName
Range("A1").Select
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,965
Messages
6,122,495
Members
449,088
Latest member
Melvetica

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