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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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