Using an Autofilter function for multiple criteria

2019-07-27 06:56发布

I have a sheet, where I would like to filter the blank rows in column T and U. I have certain cases to be considered.

I have few missing rows and have denoted them as missing in column S. If they are missing, I don't want them to be considered for filter condition. In Default they are blank.

The other case is, any one of the rows in column T and U are found blank, has to be filtered. IF both columns are blank, they also have to be filtered.

I have attached two images for reference. Could anyone suggest me how I could do it ? I am a beginner in VBA, Any lead would be helpful.

Sub FC()
Dim ws As Worksheet

Set ws = Sheets("FC")

With ws
.Range("A5:T1000").autofilter Field:=20, Criteria1:="=", Operator:=xlFilterValues
End With
End Sub

I tried the above code, It works with column T. How can I include multiple criteria? Because with my cases, with column S as missing, I don't need to consider the complete row. And with my T and U, both blank or any one is blank, then I need them to be filtered.

pic 1

This is how my sheet looks like in the beginning.

pic 2

I would like to have a code, in such a way that, I want to filter the column T and S with blank rows, any of the rows in column T and U are found blank, then I would like to filter them.

1条回答
在下西门庆
2楼-- · 2019-07-27 07:41

Ok so here's how you can achieve your custom filtering using a helper column. Let's take column Z for this mission.

Sub FC()
  With Sheets("FC").Range("Z5:Z100")
    .EntireColumn.Hidden = True  ' <-- optional, to hide the temp column
    .Formula = "=AND(S5<>""Missing"",OR(ISBLANK(T5),ISBLANK(U5)))"
    .AutoFilter 1, True
  End With
End Sub
查看更多
登录 后发表回答