vba autofilter does not contain two values

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Need your help in filtering Below data, Filter out xxxx and yyyy.
It is hardcoded, how to pass Criteria from Range. Thanks.

VBA Code:
sub autofilterDynamically
Dim arg1 as variant
arg1 = application.worksheetfunction.Transpose(Mapping.Range("A2:A3"))

'below line worked how to make it dynamic
Range("A1").currentregion.AutoFilter field:=2, Criteria1:= _
        "<>xxxx*", Operator:=xlAnd, Criteria2:="<>yyyy*"
               
'Something like this.        ' it is not working
Range("A1").currentregion.AutoFilter field:=2, Criteria1:= array("<>"& arg1),operator:= xlfiltervalues

end sub

Regards,
mg
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You can only use an array to filter on exact matches. As you only have two values use
VBA Code:
Range("A1").AutoFilter field:=2, Criteria1:= "<>"&arg1(1), Operator:=xlAnd, Criteria2:="<>"&arg1(2)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,454
Messages
6,124,933
Members
449,195
Latest member
Stevenciu

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