Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using dates with autofilter


Hi, I'm having difficulty filtering a list using auto filter as th
entire list is filtered out even though I know that the dates selecte
are in the list. Could this be a formatting issue?

Firstly, I'm using the calendar control in a user form to obtain th
start date and end dates as follows:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
Public ChosenDate1 As Date
Public ChosenDate2 As Date

Private Sub Calendar1_Click()
ChosenDate1 = Calendar1.Value
End Sub

Private Sub Calendar2_Click()
ChosenDate2 = Calendar2.Value
End Sub

Private Sub cmdAddEndDate_Click()
frmDateRange.txtEndDate = Format(ChosenDate2, "d/m/yy")
frmDateRange.lblInstruction.Caption = "Thank you, now click the 'Ru
Report' button."
End Sub

Private Sub cmdAddStartDate_Click()
frmDateRange.txtStartDate = Format(ChosenDate1, "d/m/yy")
frmDateRange.lblInstruction.Caption = "Now select an end date and clic
the 'Add End date' button."
frmDateRange.Calendar1.Visible = False
frmDateRange.Calendar2.Visible = True
End Sub

Then, I want to filter the list based on the dates but the entire lis
is filtered out. This is the code I'm using:

Private Sub cmdRunReport_Click()
Dim Begin As Date
Dim EndDate As Date

MsgBox ChosenDate1
MsgBox ChosenDate2

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

'Sort the list by item code and then date
Selection.Sort Key1:=Range("J2"), Order1:=xlAscending
Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
DataOption2 _
:=xlSortNormal

'Filter list according to date range selection
Selection.AutoFilter Field:=3, Criteria1:=ChosenDate1
Operator:=xlAnd _
, Criteria2:=ChosenDate2

'Set sub-totals report
Selection.Subtotal GroupBy:=10, Function:=xlSum
TotalList:=Array(13, 30) _
, Replace:=True, PageBreaks:=False, SummaryBelowData:=True


Range("K1").Select
Selection.EntireColumn.Hidden = True
Range("B1").Select
Selection.EntireColumn.Hidden = True
Range("D1").Select
Selection.EntireColumn.Hidden = True
Range("F1").Select
Selection.EntireColumn.Hidden = True
Range("G1").Select
Selection.EntireColumn.Hidden = True
Range("H1").Select
Selection.EntireColumn.Hidden = True

frmDateRange.Hide
End Sub

The dates seem to be fine when I step through the code but while I'
stepping through, if I look at the custom option in the date column I'
trying to filter on, the date in the selection box is in "m/d/yy" forma
and not the "d/m/yy" format set up in the code.

Is this the problem and how do I resolve this? Should I format th
dates to general numbers and convert the dates from the calenda
control to general numbers too?

Thanks for any help offered

--
skuzap
-----------------------------------------------------------------------
skuzapo's Profile: http://www.excelforum.com/member.php...fo&userid=2743
View this thread: http://www.excelforum.com/showthread.php?threadid=52835

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using dates with autofilter


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx


--
skuzapo
------------------------------------------------------------------------
skuzapo's Profile: http://www.excelforum.com/member.php...o&userid=27430
View this thread: http://www.excelforum.com/showthread...hreadid=528356

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Using dates with autofilter

Did you find a solution to this problem?
--
Adam Thwaites
Access Database Designer

Manchester, UK


"skuzapo" wrote:


Hi, I'm having difficulty filtering a list using auto filter as the
entire list is filtered out even though I know that the dates selected
are in the list. Could this be a formatting issue?

Firstly, I'm using the calendar control in a user form to obtain the
start date and end dates as follows:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
Public ChosenDate1 As Date
Public ChosenDate2 As Date

Private Sub Calendar1_Click()
ChosenDate1 = Calendar1.Value
End Sub

Private Sub Calendar2_Click()
ChosenDate2 = Calendar2.Value
End Sub

Private Sub cmdAddEndDate_Click()
frmDateRange.txtEndDate = Format(ChosenDate2, "d/m/yy")
frmDateRange.lblInstruction.Caption = "Thank you, now click the 'Run
Report' button."
End Sub

Private Sub cmdAddStartDate_Click()
frmDateRange.txtStartDate = Format(ChosenDate1, "d/m/yy")
frmDateRange.lblInstruction.Caption = "Now select an end date and click
the 'Add End date' button."
frmDateRange.Calendar1.Visible = False
frmDateRange.Calendar2.Visible = True
End Sub

Then, I want to filter the list based on the dates but the entire list
is filtered out. This is the code I'm using:

Private Sub cmdRunReport_Click()
Dim Begin As Date
Dim EndDate As Date

MsgBox ChosenDate1
MsgBox ChosenDate2

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

'Sort the list by item code and then date
Selection.Sort Key1:=Range("J2"), Order1:=xlAscending,
Key2:=Range("C2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal

'Filter list according to date range selection
Selection.AutoFilter Field:=3, Criteria1:=ChosenDate1,
Operator:=xlAnd _
, Criteria2:=ChosenDate2

'Set sub-totals report
Selection.Subtotal GroupBy:=10, Function:=xlSum,
TotalList:=Array(13, 30) _
, Replace:=True, PageBreaks:=False, SummaryBelowData:=True


Range("K1").Select
Selection.EntireColumn.Hidden = True
Range("B1").Select
Selection.EntireColumn.Hidden = True
Range("D1").Select
Selection.EntireColumn.Hidden = True
Range("F1").Select
Selection.EntireColumn.Hidden = True
Range("G1").Select
Selection.EntireColumn.Hidden = True
Range("H1").Select
Selection.EntireColumn.Hidden = True

frmDateRange.Hide
End Sub

The dates seem to be fine when I step through the code but while I'm
stepping through, if I look at the custom option in the date column I'm
trying to filter on, the date in the selection box is in "m/d/yy" format
and not the "d/m/yy" format set up in the code.

Is this the problem and how do I resolve this? Should I format the
dates to general numbers and convert the dates from the calendar
control to general numbers too?

Thanks for any help offered.


--
skuzapo
------------------------------------------------------------------------
skuzapo's Profile: http://www.excelforum.com/member.php...o&userid=27430
View this thread: http://www.excelforum.com/showthread...hreadid=528356


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
Using Autofilter to exclude dates Ian Excel Worksheet Functions 11 August 1st 08 01:41 PM
Autofilter- show dates differently lunker55 Excel Discussion (Misc queries) 3 November 10th 05 06:58 PM
autofilter with range of partial dates François Excel Programming 3 February 28th 05 02:01 PM
Dates as input to autofilter? Tobias Excel Programming 1 February 24th 05 10:53 AM
Filtering out dates using autofilter sk8rider[_3_] Excel Programming 2 June 16th 04 09:43 PM


All times are GMT +1. The time now is 06:12 PM.

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

About Us

"It's about Microsoft Excel"