VBA - Issue passing parameter for filtering

gio123bg

Active Member
Joined
Feb 14, 2004
Messages
255
Hi All,
I need to select multiple values as filter in a column.

If I use this VBA code for a single selection the code works well.

Dim Parameter As Variant

Parameter = "" & "ARGES SPA"

Selection.AutoFilter
Sheet1.Range("$A$1:$AE$24").AutoFilter Field:=3, Criteria1:=Array( _
Parameter), Operator:=xlFilterValues

If I try to set multiple selections, the filter doesn't filer values. More exactly

Parameter = "" & "ARGES SPA" & """ ,""" & "CEATIM SRL" & ""

Any suggestion well be greatly appreciated.
Thanks in advance for your kind support.
Regards,

Giovanni
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try using:

Code:
Parameter = Array("ARGES SPA", "CEATIM SRL")

and your criteria as Parameter.
 
Upvote 0
Thanks for the suggestion but I have tried to pass a string but without success.

Sheet1.Range("$A$1:$AE$24").AutoFilter Field:=3, Criteria1:=Parameter, Operator:=xlFilterValues

where

First attempt

par1 = "" & "ARGES SPA SPA" & """ ,""" & "CEATIM SRL" & ""

Parameter = Array(par1)

Second attempt

par2 = """" & par1 & """"
Parameter = Array(par2)

Hope in your help.

Thanks.

Regards,

Giovanni
 
Upvote 0
Giovanni

When you use xlFilterValues for the Operator argument and you want to filter for multiple values you need to use an array for the Criteria argument.

If you pass a string then all you'll be filtering for is that string, in this case 'ARGES SPA" ,"CEATIM SRL'.
 
Upvote 0
Didn't you like my suggestion? Why don't you like to use that because then maybe I can understand why not?
 
Upvote 0
Hi Steve, sorry. Now I have understood your suggestion. it was correct. With this VBA code now all is ok.

Sheet1.Range("$A$1:$AE$24").AutoFilter Field:=3, Criteria1:=NoDupArray, Operator:=xlFilterValues

where Criteria1 = NoDupArray
and where
Dim NoDupArray() As Variant

Loop row by row r ...
NoDupArray(r) = valuecell

Regards,
Giovanni
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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