the code works all perfect, but need to modify only on the condition if any of the Criteria is not matching.
means if AutoFilter Field:=cfind.Column, Criteria1:="Rejected" or .AutoFilter Field:=ccfind.Column, Criteria1:="" is not matching then it should exit auto filter
means if AutoFilter Field:=cfind.Column, Criteria1:="Rejected" or .AutoFilter Field:=ccfind.Column, Criteria1:="" is not matching then it should exit auto filter
VBA Code:
Sub autofiltering()
Dim col As String, cfind As Range
Dim coll As String, ccfind As Range
Sheets("Candidate Master").Select
col = "Cand. Final Status"
coll = "Email Flag"
With Worksheets("Candidate Master") '<-- reference your relevant worksheet (change "AF" to your actual worksheet name)
With .Range("A1", .Cells(1, .Columns.Count).End(xlToLeft)) '<-- reference its row 1 cells from column 1 rightwards to last not empty one
'Set cfind = .Find(what:=col, LookIn:=xlValues, lookat:=xlWhole) '<-- look for the wanted column header
Set cfind = .Rows(1).Find(what:=col, LookIn:=xlValues, lookat:=xlWhole)
Set ccfind = .Rows(1).Find(what:=coll, LookIn:=xlValues, lookat:=xlWhole)
If Not cfind Is Nothing Then '<-- if the header has been found
.AutoFilter Field:=cfind.Column, Criteria1:="Rejected"
.AutoFilter Field:=ccfind.Column, Criteria1:=""
' do your things
End If
End With
'.AutoFilterMode = False '<-- show all rows back and remove autofilter buttons
End With