Two Add Filters in One Column - Advance Filter

siddo

Board Regular
Joined
May 26, 2020
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi, I'm very new to using advanced filters in macro. I'm in a situation where I wanted to use two filters in a single column. E.g., there is a column 'Name' in that I have to put a filter on the name which has Pre-Imp and SIC; in this case, is it possible to do it? I know we can use And, Or filters in the advanced filter but think works only when the data is in different columns in my case, the data is in the same column.

Any help would be appreciated in this
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Assuming that I have understood correctly, see if you can adapt something like this to your layout & data.

My sample data before:

siddo.xlsm
ABCDE
1DateNameAmount
21/01/2023Other 11
32/01/2023Pre-Imp2
43/01/2023Pre-Imp3
54/01/2023SIC4
65/01/2023Other 25
76/01/2023Other 36
87/01/2023Pre-Imp7
9
10
Sheet1


VBA Code:
Sub AF()
  Dim rCrit As Range
  
  With Range("A1").CurrentRegion
    Set rCrit = .Offset(, .Columns.Count).Resize(2, 1)
    rCrit.Cells(2).Formula = "=OR(B2=""Pre-Imp"",B2= ""SIC"")"
    .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
  End With
  rCrit.Cells(2).ClearContents
End Sub

After:

siddo.xlsm
ABCDE
1DateNameAmount
32/01/2023Pre-Imp2
43/01/2023Pre-Imp3
54/01/2023SIC4
87/01/2023Pre-Imp7
9
10
Sheet1
 
Upvote 0
Thank you for replying Peter, I get the steps that you proposed however in my case I wanted to select values that have pre-imp and SIC in a single cell, not sure if I just use wildcard it would help me over here
 
Upvote 0
If this doesn't do it then can we have a representative sample of data in the name column so that we don't have to guess the sorts of variation that you might have?

siddo.xlsm
ABCDE
1DateNameAmount
21/01/2023Other 11
32/01/2023Pre-Imp & SIC2
43/01/2023Pre-Imp3
54/01/2023SIC or Pre-Imp4
65/01/2023Other 25
76/01/2023SIC, Pre-Imp6
87/01/2023Pre-Imp7
9
10
Sheet1


VBA Code:
Sub AF_v2()
  Dim rCrit As Range
  
  With Range("A1").CurrentRegion
    Set rCrit = .Offset(, .Columns.Count).Resize(2, 1)
    rCrit.Cells(2).Formula = "=AND(SEARCH(""SIC"",B2),SEARCH(""Pre-Imp"",B2))"
    .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=rCrit, Unique:=False
  End With
  rCrit.Cells(2).ClearContents
End Sub

siddo.xlsm
ABCDE
1DateNameAmount
32/01/2023Pre-Imp & SIC2
54/01/2023SIC or Pre-Imp4
76/01/2023SIC, Pre-Imp6
9
10
Sheet1
 
Upvote 0
Yes, this is the one I wanted, Thank you
 
Upvote 0
You're welcome. Thanks for the confirmation.

Again, not really knowing anything about what is possible in that column, be aware that the code would show a row with, for example, "Supre-Impossible Basics" in the column.
 
Upvote 0
Got it, I'm stuck with this scenario again 'TMKOC Tool Custom PPE SIC 3 Pre-imp implement', what should I do in this case?
 
Upvote 0
what should I do in this case?
You haven't said what the problem is or what you want to happen. I can't guess.
With the code I provided, a line with that in the name column would be visible.
 
Upvote 0
My problem over here is that my data lies on column F, and I'm unable to modify your code for column F, its not working for me, can you please guide me a little bit?
 
Upvote 0
My problem over here is that my data lies on column F,
All of your data is in column F? I expect not.
What are the columns that need to be included in the filtered data? For example, with my sample data above it was columns A:C.
What is a vacant column that can be used to briefly put the Advanced Filter criteria in? For me it was column D.
Perhaps you could show a sample of at least part of your worksheet (any sensitive data disguised) with XL2BB like I did?
 
Upvote 0

Forum statistics

Threads
1,216,189
Messages
6,129,408
Members
449,509
Latest member
ajbooisen

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