Filter multiple criteria not working with numbers

MeghaJ

Board Regular
Joined
Jul 2, 2009
Messages
102
Dear All,
I refereed to one of the post in this forum and got below code for multiple criteria filetr
Code:
Sub aTest()
    Dim v As Variant
    
    v = Application.Transpose(Range("MyList"))
    Range("A1").Select
    Selection.AutoFilter Field:=1, Criteria1:=v, Operator:=xlFilterValues
End Sub

This same code is not working if i have all numbers. It does not show any filtered value.

What could be the problem? This code works awesome if i just add some text in filetr condition and raw data.

please help.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try changing this line
Code:
v = Split(Join(Application.Transpose(Range("MyList"))))
 
Upvote 0
Hi Peter,

Yes, it works with your suggestion. Curious that it works differently with numbers...

M.
 
Upvote 0
Hi Peter,

Yes, it works with your suggestion. Curious that it works differently with numbers...

M.
Yes, despite the data being numerical, the array being passed in as criteria must be a String array. The Join/Split forces that conversion.
 
Upvote 0
Hi
I am using the above code, my one problem, it searches only EXACT strings suppose I want to filter out all the cells containing "cat" in any form like "I have a cat" or "you have a cat which is very cute".
If I use filter string in cell as *cat* then it works only for the last filter not all.
My filter substrings are
*commented on*
*fat*
*dog*
*cat*

but it works only for *cat*
I changed many times but I works only with the last of named range cell.
I hope you understand.

what should I do to use the wildcards?

Thank You!
 
Upvote 0
I fixed it :) But I don't like the solution I worked out!
It uses loop
For LC = 1 To UBound(v)

Columns("A:A").Select
'Selection.AutoFilter Field:=1, Criteria1:=v, Operator:=xlFilterValues
'Selection.AutoFilter Field:=1, Criteria1:=v, Operator:=xlOr
Selection.AutoFilter Field:=1, Criteria1:=v(LC), Operator:=xlFilterValues
'
Cells.Select
Range("A42").Activate
Selection.ClearContents
Next

LC is loop counter
v is array
I want a solution without loop (if it is faster since I have to operate on 10k+ cells in one go :(

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,744
Messages
6,174,252
Members
452,553
Latest member
red83

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