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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,827
Office Version
  1. 365
Platform
  1. Windows
Try changing this line
Code:
v = Split(Join(Application.Transpose(Range("MyList"))))
 
Upvote 0

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,100
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
Hi Peter,

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

M.
 
Upvote 0

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,827
Office Version
  1. 365
Platform
  1. Windows
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

Engr Warsi

New Member
Joined
May 6, 2017
Messages
2
ADVERTISEMENT
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

Engr Warsi

New Member
Joined
May 6, 2017
Messages
2
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,195,654
Messages
6,010,935
Members
441,575
Latest member
JOHNNY18031

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
Top