Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Autofilter a Date range
Hi
When I use the below code the autofilter conditions StartDate and EndDate dosn't work. Nothing is in the "Custom filter" if I look after running the filter. If I remove the Clng command the dates are placed in the autofilter but it dosn't work. If I reactivate it after this everything i ok. Any help? Private Sub cmdOK_Click() Dim StartDateInt, EndDateInt As Integer Sheets("Graf Data").Visible = True Sheets("Graf Data").Activate Columns("A:X").Select Selection.EntireColumn.Hidden = False With ActiveSheet If .FilterMode Then .ShowAllData End If End With StartDate = txtStartDate.Value EndDate = txtEndDate.Value MaxDate = Format(Range("C459").Value, "yyyy.mm.dd") MinDate = Format(Range("C3").Value, "yyyy.mm.dd") If txtStartDate.Value = "" Or txtEndDate.Value = "" Or StartDate EndDate Then MsgBox ("You need to giv both a Start and End Date or StartDate later than EndDate") txtStartDate.SetFocus ElseIf StartDate < CDate(Range("C3").Value) Or EndDate CDate(Range("C459").Value) Then MsgBox ("StartDate " & StartDate & " EndDate: " & EndDate & " MinDate " & MinDate & " MaxDate " & MaxDate) txtStartDate.SetFocus Else MsgBox (StartDateInt) Selection.AutoFilter Field:=3, Criteria1:="=" & CLng(StartDate), Operator:=xlAnd, Criteria2:="<=" & CLng(txtEndDate.Value) If optMonth = True Then Selection.AutoFilter Field:=1, Criteria1:="<" ElseIf optWeek = True Then Selection.AutoFilter Field:=2, Criteria1:="<" End If End If Sheets("Graf Data").Visible = False Sheets("Statistics").Activate Application.ScreenUpdating = True Application.EnableEvents = True End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Return info based on Date Range | Excel Worksheet Functions | |||
Advanced filter a dynamic date range | Excel Worksheet Functions | |||
Crate group of date, with Dynamic Range in pivot table not working | Excel Discussion (Misc queries) | |||
Date Range within one cell | New Users to Excel | |||
Date Range and calculation | Excel Worksheet Functions |