I need to use VBA to filter some information in excel. As I have an excel with 20 columns, now want to use AutoFilter function to search in some columns if it contains one value (Ex: ID010). what i want is it’ll display all rows that have at least one column contains ID010.
Currently, i use the below code to search. However, it could not find any data because all the criteria seem to tie together using AND operator
' Search range, [argIn]---> search value
With [D5:M65536]
.AutoFilter Field:=4, Criteria1:=argIn
.AutoFilter Field:=5, Criteria1:=argIn
.AutoFilter Field:=6, Criteria1:=argIn
.AutoFilter Field:=7, Criteria1:=argIn
.AutoFilter Field:=8, Criteria1:=argIn
.AutoFilter Field:=9, Criteria1:=argIn
.AutoFilter Field:=10, Criteria1:=argIn
.AutoFilter Field:=11, Criteria1:=argIn
.AutoFilter Field:=12, Criteria1:=argIn
.AutoFilter Field:=13, Criteria1:=argIn
End With
I wonder if anyone could give me some hints or examples how to handle this issue.
Thank you in advance.
The autofilter functionality won’t help you here, as you’ve discovered the behaviour is to AND the filters together.
One approach would be to have a control column in the spreadsheet (perhaps maintained through VBA) populated with worksheet functions like
And then apply the filter to the control column.