VBA Filter

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
What would be the best way to filter a worksheet where I need to filter by If "this" or "this" but doesn't contain "this"

below im filtering a table looking for "Se Mo" or "Sc Qu" then wanting to exclude any rows returned that contains 2012.

Didn't think this would be this hard.

Suggestion?


.AutoFilterMode = False
With .Range("A1:H" & LastRow)
.AutoFilter Field:=5, Criteria1:=Array("=*Se Mo*", "=*Sc Qu*", "<>*2012*"), Operator:=xlFilterValues
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You can only use more than 2 criteria in an autofilter when filtering on an exact match.
1 option is to put a formula into an empty column that shows which rows should be hidden & filter on that.
Another option would be to use advanced filters.
Failing that you would need to get all the cell values to show & put that into an array, that you could then use to filter.
 
Upvote 0
Thanks Fluff,

i went down the Advanced filter lane last week and found that its not to forgiving if i have blank rows which i do. Before i beat that drum again, can you give me more info on using a inserted column using a formula. I know i can insert a blank column and insert formulas from vba, but lost or inserting a formula. Just what would the formula say... sorry for being so lost.

Thanks
 
Upvote 0
You could use something like
=AND(ISERROR(FIND("2012",E2)),OR(ISNUMBER(SEARCH({"Se Mo","Sc QU"},E2))))

Change Search to Find if you want it case sensitive.
 
Upvote 0
Thanks.

this is an array formula - correct? do i have to do anything special to other than copy and paste into my vba
 
Upvote 0
Not sure if it needs array entry or not, try putting it into the sheet manually & see what happens.
 
Upvote 0
Kewl, not a arrayformula. For the lines containing 2012 it only marks the row false when column E2 starts with a 2012 and nothing else on the line. i could have abc 2012 def in the line and would want it marked false

=AND(ISERROR(FIND("2012",E2)),OR(ISNUMBER(SEARCH({"Se Mo","Sc QU"},E2))))

Thanks
 
Upvote 0
Works for me

+Fluff New.xlsm
EF
1
2se moTRUE
3se mo 2012FALSE
4sc quTRUE
5sc qu 2012FALSE
Lookup
Cell Formulas
RangeFormula
F2:F5F2=AND(ISERROR(FIND("2012",E2)),OR(ISNUMBER(SEARCH({"Se Mo","Sc QU"},E2))))


Does it make any difference if you array enter it?
 
Upvote 0
wow, i rekeyed the formula you provided and all is working. Im think i've exhausted office365 today.

Thanks for the help. I would not have thought of using the formula to achieve my needs.

Have a super weekend.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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