Ax8472
05-28-2017, 05:01 AM
Hi everyone.
I'm hoping someone can be kind enough to look into this for me, I already asked on Ozgrid but I think I have people stumped.
I'm looking to VBA some code for an autofilter to filter some dates. The dates change every time. I can set these dates into some cells, they're currently set as mm/dd/yyyy format dates.
Sub Macro15()
'
' Macro15 Macro
'
'
ActiveSheet.Range("$K$20:$Q$58").AutoFilter Field:=3, Criteria1:= _
">=" & Worksheets(1).Range("AA16"), Operator:=xlAnd, Criteria2:=Worksheets(1).Range("AB14")
End Sub
See the first date? Works like a charm. ">=" & Worksheets(1).Range("AA16").
But the second one doesn't... Criteria2:=Worksheets(1).Range("AB14") if I change this one to a static date then the code works fine.
I then thought maybe it was the source data of the cell used for the second criteria, but I used those cells for the first criteria and it worked fine, so it's nothing to do with the cells.
if anyone can help me with this, it'd be such a huge help! <3
EDIT : Forgot to say. When I say the code doesn't work, what I mean is, it filters with no results. No error as such but it just gives me nothing. If I change it to a date, it shows the correct data. :) I'm using Excel 2007.
19310
I'm hoping someone can be kind enough to look into this for me, I already asked on Ozgrid but I think I have people stumped.
I'm looking to VBA some code for an autofilter to filter some dates. The dates change every time. I can set these dates into some cells, they're currently set as mm/dd/yyyy format dates.
Sub Macro15()
'
' Macro15 Macro
'
'
ActiveSheet.Range("$K$20:$Q$58").AutoFilter Field:=3, Criteria1:= _
">=" & Worksheets(1).Range("AA16"), Operator:=xlAnd, Criteria2:=Worksheets(1).Range("AB14")
End Sub
See the first date? Works like a charm. ">=" & Worksheets(1).Range("AA16").
But the second one doesn't... Criteria2:=Worksheets(1).Range("AB14") if I change this one to a static date then the code works fine.
I then thought maybe it was the source data of the cell used for the second criteria, but I used those cells for the first criteria and it worked fine, so it's nothing to do with the cells.
if anyone can help me with this, it'd be such a huge help! <3
EDIT : Forgot to say. When I say the code doesn't work, what I mean is, it filters with no results. No error as such but it just gives me nothing. If I change it to a date, it shows the correct data. :) I'm using Excel 2007.
19310