Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 104
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return info based on Date Range kermitforney Excel Worksheet Functions 3 July 11th 06 07:59 PM
Advanced filter a dynamic date range oneandoneis2 Excel Worksheet Functions 2 April 6th 06 08:57 AM
Crate group of date, with Dynamic Range in pivot table not working Tiya Excel Discussion (Misc queries) 3 March 1st 06 02:26 PM
Date Range within one cell Cachod1 New Users to Excel 5 October 18th 05 03:30 AM
Date Range and calculation vgreen Excel Worksheet Functions 2 August 23rd 05 11:08 AM


All times are GMT +1. The time now is 11:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"