Advanced Filter not filtering

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
It is probably a dumb mistake but I am not seeing it. All this code runs all the way through but does not filter the results.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim DataRange As Range
Dim FilterRange As Range
Dim DestinationRange As Range
Set DataRange = DataSheet.Range("A1").CurrentRegion
Set FilterRange = DinD.Range("C4:C6")
Set DestinationRange = DinD.Range("C37").CurrentRegion
If Target.Address = "$C$5" Then
    
    Application.EnableEvents = False
    DestinationRange.Offset(1).ClearContents
    DataRange.AdvancedFilter xlFilterCopy, FilterRange, DestinationRange
    Application.EnableEvents = True
    
End If
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
1. CopyTo range, DestinationRange, must be the activesheet. So, there is no need for a DinD for it.

2. If formulas in the criterion range, set them as hardcoded values.
 
Upvote 0
That code works happily for me. Are you sure the change event is being triggered?
Also which sheet is the code in?
 
Upvote 0
OK so I changed it to this and still not filtering. Please explain further what #2 means...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim DataRange As Range
Dim FilterRange As Range
Dim DestinationRange As Range
Set DataRange = DataSheet.Range("A1").CurrentRegion
Set FilterRange = Range("C4:C6")
Set DestinationRange = Range("C37").CurrentRegion
If Target.Address = "$C$5" Then
    
    Application.EnableEvents = False
    DestinationRange.Offset(1).ClearContents
    DataRange.AdvancedFilter xlFilterCopy, FilterRange, DestinationRange
    Application.EnableEvents = True
    
End If
End Sub
 
Upvote 0
Does C4 match the one of the headers in the data range?
Also you are triggering the filter if C5 is changed, what is in C6?
 
Upvote 0
Does C4 match the one of the headers in the data range?
Also you are triggering the filter if C5 is changed, what is in C6?

Copied and Pasted header. I can double check to b sure. Nothing in C6 yet. Are both required to filter? I thought the second line was an or function
 
Upvote 0
Hummmmm…… when I put a value in C6 it worked. I am filtering by a date range. How can I do it if they only fill in a start date?

I want either anything before or after a date or;
anything between two dates
 
Last edited:
Upvote 0
What exactly you putting in C5 & 6?
If I leave one of them empty I get the entire data set.
 
Upvote 0
What exactly you putting in C5 & 6?
If I leave one of them empty I get the entire data set.

That is exactly my problem. C5 is a start date (>=8/15/2019) and C6 is the end date. What if they want everything after the start date or everything before the end date? ie everything since 8/1/2019
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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