Filter Data Using List From Another Sheet

justme101

Board Regular
Joined
Nov 18, 2017
Messages
67
Office Version
  1. 365
Platform
  1. Windows
Hey guys,

So the title is self-explanatory, i have data in one sheet where i want to put a filter in column F of the active sheet (named "RawData") using the list of filter criteria in Column A of a DIFFERENT sheet (Named "Rules").

I got the following code from the net after a lot of searching and modifications:

Dim vCrit As Variant
Dim wsO As Worksheet
Dim wsL As Worksheet
Dim rngCrit As Range
Dim rngOrders As Range
Set wsO = Worksheets("RawData")
Set wsL = Worksheets("Rules")
Set rngOrders = wsO.Range("$A$1").CurrentRegion
Set rngCrit = wsL.Range("FunctionList")


vCrit = rngCrit.Value


rngOrders.AutoFilter _
Field:=6, _
Criteria1:=Application.Transpose(vCrit), _
Operator:=xlFilterValues

I already named the list of criteria as "FunctionList" and it is working perfectly.

The PROBLEM i am facing is that this code works for a column where data is only in LETTERS (for e.g. ABC, XYZ etc) . I tried the same code on a column which has numbers in the cells and the filter is activated but it does not show me any data or in other words, hides ALL the rows containing the data.

A sample data set is given below:

FilterCriteria12
23123AF
23454FAFASD
4656EHFD
657AHK
9999AHBFA
9999AFDAD
443412ASAVHHY
9999YDGTYD
22SDDFGS

<tbody>
</tbody>

Now, in another sheet there is this column where i have the list through which i want to filter:

FilterList
9999
657
120

<tbody>
</tbody>


In this case, the macro should filter out the data with these 3 criteria and if there is no criteria match or only some data match,then filter only with those data then move on with the next step (which i will write later on after this macro is made). As i said, this list will change on a weekly basis but for the life of me i cannot see what is wrong with this. Please let me know if you need clarifications. Thank you.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
The array criteria must be an array of strings, not numbers.
To convert the array of numbers to an array of strings try

Code:
Sub aTest()
    Dim vCrit As Variant
    Dim wsO As Worksheet
    Dim wsL As Worksheet
    Dim rngCrit As Range
    Dim rngOrders As Range
    
    Set wsO = Worksheets("RawData")
    Set wsL = Worksheets("Rules")
    
    Set rngOrders = wsO.Range("$A$1").CurrentRegion
    Set rngCrit = wsL.Range("FunctionList")
    
    [COLOR=#ff0000]vCrit = Split(Join(Application.Transpose(rngCrit.Value)))[/COLOR]
    
    rngOrders.AutoFilter _
    Field:=6, _
    Criteria1:=[COLOR=#ff0000]vCrit[/COLOR], _
    Operator:=xlFilterValues
End Sub

Hope this helps

M.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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