Advanced Filter Problem

anwilson

New Member
Joined
Apr 17, 2019
Messages
13
I have a large list of items that need filtered using 2 criteria. I currently have:

q1 = sh2.Range("B11").Value
If q1 = "Y" Then
sh1.Range("A2").AutoFilter 10, "Y"
ElseIf q1 = "N" Then
sh1.Range("A2").AutoFilter 10, "N"
End If

What I need it to do is if cell B11 on sheet 1 is answered with "N" I need it to filter field 10 on sheet 2 with all the "N" and blank cells, if cell B11 on sheet 1 is answered with "Y" I need it to filter field 10 on sheet 2 with all the "Y" and blank cells.

Any help is appreciated as I am new to the vba world.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello AnWilson,

Try the following code placed in the Sheet1 module:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
If Intersect(Target, Range("B11")) Is Nothing Then Exit Sub
If Target.Value = vbNullString Then Exit Sub

Application.ScreenUpdating = False

   With Sheet2.[A1].CurrentRegion
        .AutoFilter 10, Target, xlOr, ""
   End With

   Sheet2.Select

Application.ScreenUpdating = True

End Sub

The code assumes that the data on Sheet2 starts in Row2 with headings in Row1. Once you place a value ("Y", "N") in Sheet1, cell B11, the code will filter the data in Sheet2 showing "Y" and blanks or "N" and blanks.

This code just filters the data in Sheet2. I'm not sure what you wish to do with it once it is filtered.

To implement the code:-
- Right click on the Sheet1 tab.
- Select "View Code" from the menu that appears.
- In the big white code field that then appears, paste the above code.

I hope that this helps.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
You're welcome. I'm glad that I was able to assist.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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