VBA - Advanced filter with ever expanding criteria

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,291
Office Version
  1. 365
Platform
  1. Windows
I have a Advanced filter that works as expected, however I would like the user to be able to add additional criteria into two of the columns so more and more information is filter out each time.



This is the working filter.

Code:
Sheets("data").Range("A5:Z10000").AdvancedFilter _
        Action:=xlFilterCopy, _
        CriteriaRange:=Sheets("Filter_No_Ack").Range("A1:C2"), _
        CopyToRange:=FS.Range("A12"), _
        Unique:=False


I have another routine that adds date to the bottom of columns B & C

A never changes, only A2 will contain a criteria


I changed my advanced filter to a much bigger range, but now all data is returned.

Code:
Sheets("data").Range("A5:Z10000").AdvancedFilter _
        Action:=xlFilterCopy, _
        CriteriaRange:=Sheets("Filter_No_Ack")[COLOR=#ff0000].Range("A1:C2000"),[/COLOR] _
        CopyToRange:=FS.Range("A12"), _
        Unique:=False

I tried
Code:
[COLOR=#303336][FONT=inherit]SkipBlanks[/FONT][/COLOR][COLOR=#303336][FONT=inherit]:=[/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]True[/FONT][/COLOR]
but this returned no data.


Any ideas how to have a big range with lots of blank criteria?

My criteia will look like this

[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]Ack[/TD]
[TD="class: xl65, width: 64"]Code[/TD]
[TD="class: xl65, width: 64"]Order[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]<>RSC[/TD]
[TD]<>*069519[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]<>POL[/TD]
[TD]<>*065223[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]<>TOP[/TD]
[TD]<>*063254[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]<>*063221[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]<>*063458[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I think I am confused with AND / OR operations?
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
what code do you get if you record your filter actions
 
Upvote 0
I get an error that i can only filter data to the activesheet?
 
Upvote 0
Got it...

Code:
Sub filter_tmp_Code()
'
' filter_tmp_Code Macro
'


'
    Sheets("Data").Range("A5:Z10000").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Sheets("Filter_No_Ack").Range("A1:C3000"), CopyToRange:= _
        Range("A12"), Unique:=False
End Sub



I edited my original post with a bit more info


[TABLE="class: cms_table, width: 192"]
<tbody>[TR]
[TD="class: cms_table_xl65, width: 64"]Ack[/TD]
[TD="class: cms_table_xl65, width: 64"]Code[/TD]
[TD="class: cms_table_xl65, width: 64"]Order[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]<>RSC[/TD]
[TD]<>*069519[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]<>POL[/TD]
[TD]<>*065223[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]<>TOP[/TD]
[TD]<>*063254[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]<>*063221[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]<>*063458[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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