LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with passing date value into Auto filter criteria

Please can someone help me with a spreadsheet that has been working OK
until this year.

The sheet has a list of dates, there also is a date entered in a cell
which is used as a variable. The format of both the variable and the
list are identical.
The code is below.

Option Explicit

Dim FilterPeriod As String 'Used by subs UpdateChart and
CreatePareto for filtering on graphs
Dim TotalComplaintsFilterPeriod As String 'holds the entended filter
preiod required by the Totals Line Chart (i.e. 3 years)

Sub newmonth()

FilterPeriod = Sheets(1).Range("a2").Value
FilterPeriod = DateAdd("yyyy", -1, FilterPeriod)
FilterPeriod = Format(FilterPeriod, "dd/mmm/yy")
TotalComplaintsFilterPeriod = DateAdd("yyyy", -2, FilterPeriod)
TotalComplaintsFilterPeriod = Format(TotalComplaintsFilterPeriod,
"mmm-yy")

Selection.AutoFilter Field:=1, _
Criteria1:="=" & TotalComplaintsFilterPeriod, Operator:=xlAnd


End Sub

If I run the macro using Dec-03 or earlier dates the macro works OK.
If I use Jan-04 or any future dates then the macro falls over.
Interestingly if I query the custom value in the autofilter, on my
machine at work the value that is being passed into the criteria field
from the TotalComplaintsFilterPeriod variable is the serial format,
whereas on my PC at home it returns it in the dd/mm/yy format.
Why should this macro stop working all of a sudden and why should the
two machines be different.

Thanks in advance for any solutions.

Should anyone require a simplified version of the spreadsheet just
with the macro and a sample data set please drop me an email.

John C.
 
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
Auto Filter function only provide 2 criteria input Kent Excel Worksheet Functions 5 June 4th 07 04:17 PM
Auto Filter - capture criteria used Kolotti Excel Discussion (Misc queries) 2 January 30th 07 05:05 PM
Is it possible to use auto filter to select more than 2 criteria? hello_lpc Excel Discussion (Misc queries) 2 July 12th 06 02:52 PM
Auto Filter by Criteria Bunson Excel Worksheet Functions 1 June 7th 06 11:03 PM
Help with using filter criteria with date [email protected] Excel Worksheet Functions 1 December 14th 05 07:31 PM


All times are GMT +1. The time now is 04:33 AM.

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"