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
 
Not sure why it's not working for you.
As a matter of interest are your dates hard values, or the result of formulae?
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
It is my understanding that a row are "and" criteria and columns are "or" criteria.

I think the second value being null negates the first value because the filter heading is the same. Which is why I was trying two rows but that did not work either.
 
Upvote 0
Sorry I couldn't have been more help & thanks for the feedback
 
Upvote 0
If anyone is reading this later here is the final code that hardcodes in the missing dates and makes it work. Hope it helps someone else.

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("J6").CurrentRegion
Set DestinationRange = Range("C37").CurrentRegion
If Target.Address = "$E$6" Or Target.Address = "$F$6" Then
    
    If IsDate(DinD.Range("E6")) Then
        DinD.Range("J6") = ">=" & DinD.Range("E6")
    Else
        DinD.Range("J6") = ">=1/1/1900"
    End If
    
    If IsDate(DinD.Range("F6")) Then
        DinD.Range("K6") = "<=" & DinD.Range("F6")
    Else
        DinD.Range("K6") = "<=" & Date
    End If
    
    Application.EnableEvents = False
    DestinationRange.Offset(1).ClearContents
    DataRange.AdvancedFilter xlFilterCopy, FilterRange, Range("C37").CurrentRegion
    Application.EnableEvents = True
    
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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