ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Not filtering by date (https://www.excelbanter.com/excel-programming/318444-not-filtering-date.html)

chOcO

Not filtering by date
 
i've tried the code below but it does not seems to filter out the
recent 2 weeks entries. Kinda stumped here and will appreciate any
help. Thanks!

Private Sub filterp_Click()

Dim Class As String
Dim FilterRange As Range
Dim myDate As Date
Class = ComboBox1.Value

myDate = Format(Date - 14, "dd/mm/yy")
Range("A1").Select
Selection.AutoFilter
Set FilterRange = ActiveSheet.Range("A1:AK" & _
ActiveSheet.Range("A65536").End(xlUp).Row)
FilterRange.AutoFilter Field:=1, Criteria1:=Class, Operator:=xlAnd, _
Field:=9, Criteria1:="=" & myDate

End Sub


Dave Peterson[_5_]

Not filtering by date
 
Sometimes working with the value of the dates makes life easier:

Private Sub filterp_Click()

Dim Class As String
Dim FilterRange As Range
Dim myDate As Date
Class = ComboBox1.Value

myDate = Date - 14 'no need to format it

Range("A1").Select
Selection.AutoFilter
Set FilterRange = ActiveSheet.Range("A1:AK" & _
ActiveSheet.Range("A65536").End(xlUp).Row)
FilterRange.AutoFilter Field:=1, Criteria1:=Class, Operator:=xlAnd, _
Field:=9, Criteria1:="=" & clng(myDate) '<-- note the clng() change

End Sub

chOcO wrote:

i've tried the code below but it does not seems to filter out the
recent 2 weeks entries. Kinda stumped here and will appreciate any
help. Thanks!

Private Sub filterp_Click()

Dim Class As String
Dim FilterRange As Range
Dim myDate As Date
Class = ComboBox1.Value

myDate = Format(Date - 14, "dd/mm/yy")
Range("A1").Select
Selection.AutoFilter
Set FilterRange = ActiveSheet.Range("A1:AK" & _
ActiveSheet.Range("A65536").End(xlUp).Row)
FilterRange.AutoFilter Field:=1, Criteria1:=Class, Operator:=xlAnd, _
Field:=9, Criteria1:="=" & myDate

End Sub


--

Dave Peterson

chOcO

Not filtering by date
 
hi Dave,

tried changing the code but still the same. it's showing results as far
back as yr2003. My dates are entered in the dd/mm/yy format.


chOcO

Not filtering by date
 
hi Dave,

tried changing the code but still the same. it's showing results as far
back as yr2003. My dates are entered in the dd/mm/yy format.


Dave Peterson[_5_]

Not filtering by date
 
Sometimes, I've changed the column with dates to be formatted as General.

Then did the filter and then later redid the formatting back to a nice date
format.

If that's too ugly, maybe you could insert a helper column and do the
equivalent.



chOcO wrote:

hi Dave,

tried changing the code but still the same. it's showing results as far
back as yr2003. My dates are entered in the dd/mm/yy format.


--

Dave Peterson


All times are GMT +1. The time now is 01:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com