View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jim[_74_] Jim[_74_] is offline
external usenet poster
 
Posts: 12
Default Help please with autofilter and dates

I'm having some trouble using vba to to autofilter some data based on the
date in column A of worksheet named Test
The filter appears to work if I do it manually
Column A is formatted as a date (dd/mm/yyyy)
Would one (or more ) of you gurus please assist by pointing out the error(s)
in the code below

Windows XP Pro
MS Excel 2003

Regards and TIA
Jim Burton
-----------------------

Dim StartDate As Date
Dim EndDate As Date

StartDate = Format(InputBox("Enter Start date for the report" ),
"dd/mm/yyyy")

'error traps removed for clarity

EndDate = Format(InputBox("Enter End date for the report"), "dd/mm/yyyy")

'error traps removed for clarity

With Sheets("Test)")
If AutoFilterMode = True Then .AutoFilterMode = False
.Columns("A:G").Select
With Selection
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="=" & StartDate,
Operator:=xlAnd, Criteria2:="<=" & EndDate
Selection.AutoFilter Field:=3, Criteria1:="<"
Selection.AutoFilter Field:=7, Criteria1:="="
End With

With Sheets("Test").PageSetup
.PrintArea = "$A:$F"
.CenterHeader = "&""Comic Sans MS,Bold Italic""&14Test Macro"
End With
ScreenUpdating = True
Sheets("Test").PrintPreview
ScreenUpdating = False
.AutoFilterMode = False
End With