Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 29

Thread: Solved: Filtering Dates

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location

    Solved: Filtering Dates

    In Excel 2007 I would like to filter a column of dates to show just those rows of data that fall within a selected financial year. Could someone show me how this is done please?

    I can setup manually a financial year by using Date Filters, Custom Filter and enter a Start date & a Finish date, but I was hoping to have the option of selecting it from the options available under Date Filters.

    Also can I then select particular month within a predetermined financial year?

    If this is not possible, can it be setup with VBA?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I never knew about Custom Date filters -- thanks

    I only have a brute force way which is to add 2 additional columns with

    [VBA]
    =IF(MONTH(A2)>6,"FYR"&YEAR(A2)+1,"FYR"&YEAR(A2))

    and

    =MONTH(A2)
    [/VBA]

    in them and filter on that

    I have US Gov Fiscal Year UDF, but it's nothing more than the formula in VBA and also used in a seperate column

    Paul

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I see that Paul has posted but I looked this up for you so I'll post it.

    Ted, I don't know if it will help or not but in the first textbox of the userform type 1/7/2006 and it will retreive the dates for 365 days ahead.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Thanks Paul. I had gone back and extended the date range to include dates from additional years just to further experiment. Excel will then offer filter ranges based on years, with subfilters based on months.

    Sadly it seems that they didn't allow filtering on financial years.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I missed some formatting......

    try this one Ted.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by lucas
    I misses some formatting......

    try this one Ted.
    Thanks Steve, the real data will be some 9 columns wide and a growing number of rows,so referring to a static range may be an issue. Off to work now, so will be unable to test and or experiement with your code further for some time.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you saved your data in a SQL Server DB, then created a SQL Server Data Warehouse, and then created an Analysis Services cube, you could add a financial year dimension to that, and then pivot the cube to look at either calendar year or financial year - easy peasy!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Add a helper column and a table of week numbers
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by xld
    If you saved your data in a SQL Server DB, then created a SQL Server Data Warehouse, and then created an Analysis Services cube, you could add a financial year dimension to that, and then pivot the cube to look at either calendar year or financial year - easy peasy!
    I ask for an excape stategy, and Bob gives me Einstein's theory of relativity in 4 different languages......... (Sigh) He is so English.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    MD, thank you for your file. I was wondering if the following was possible

    [vba]Sub AnalysisServicesCube1()
    Dim Yr As Long, StartDate As Date, EndDate As Date, Crit1 As String, Crit2 As String
    If ActiveSheet.AutoFilterMode Then
    ActiveSheet.Columns(1).AutoFilter
    Exit Sub
    End If

    Yr = Range("j3")
    StartDate = "1/7/" & Yr
    EndDate = "30/6" & (Yr + 1)


    Crit1 = ">=" & StartDate
    Crit2 = "<" & EndDate

    ActiveSheet.Columns(1).AutoFilter field:=1, Criteria1:=Crit1, Criteria2:=Crit2, Operator:=xlAnd

    End Sub[/vba]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Any Ideas? Somehow the Values for StartDate & EndDate show as 12:00 time value rather than 1/7/year chosen or 30/6/year chosen
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You had a slash missing after the 6 on end date but this works for me if there is a date in j3

    [VBA]Sub AnalysisServicesCube1()
    Dim Yr As Long, StartDate As Date, EndDate As Date, Crit1 As String, Crit2 As String
    If ActiveSheet.AutoFilterMode Then
    ActiveSheet.Columns(1).AutoFilter
    Exit Sub
    End If

    Yr = Range("j3")

    StartDate = "1/7/" & Yr
    MsgBox StartDate

    EndDate = "30/6/" & (Yr + 1)
    MsgBox EndDate
    ' Crit1 = ">=" & StartDate
    ' Crit2 = "<" & EndDate
    '
    ' ActiveSheet.Columns(1).AutoFilter field:=1, Criteria1:=Crit1, Criteria2:=Crit2, Operator:=xlAnd
    '
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    And so it does for me too, but it refuses to filter.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  14. #14
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    "Refuses to filter" is a bit harsh as it filters out everything, even the data I wanted to see.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    It works for me if you put a date in j3

    see attached.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Aussiebear --- can I ask how you intend to use this?

    I get the impression that it's a reatively simple list that you want to filter

    ... the real data will be some 9 columns wide and a growing number of rows
    So far it looks like there's not any Aussie Fiscal Year (Jul-Jun) filter options (like there's no US Gov fiscal year (Oct-Sep) options).

    If you were going to use a pivot table or something equivalent, I've found that a help column (as someone called it) using a UDF or a WS formula gives the most flexibility, and has the advantage of being unambigiously selectable (FY2010, FY2011, etc.)

    Just my two cents

    Paul

  17. #17
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Paul, Once I gain an understanding of this concept, I will be applying it to share portfolio data ( particularly dividend data). I will need to be able to filter out a predetermined financial year,so a copy can be sent off to the Accountants.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  18. #18
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Aussiebear
    "Refuses to filter" is a bit harsh as it filters out everything, even the data I wanted to see.
    Make sure that the criteria is formatted the same as the data, autofilter is very picky with dates. (I still say an OLAP cube is best )
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  19. #19
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I will be applying it to share portfolio data ( particularly dividend data). I will need to be able to filter out a predetermined financial year,so a copy can be sent off to the Accountants.
    I like to seperate the data from the processing. So another approach to think about would be to

    1. Have all user data on one sheet
    2. One Sub to read data sheet, check completeness, format, etc. (dates are dates, required numbers are entered, etc.)
    3. Another Sub to select, copy and format to seperate Output sheet; only right year would go over, data re-arranged, etc.
    4, Format output sheet

    Just thoughts

    Paul

  20. #20
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by xld
    Make sure that the criteria is formatted the same as the data, autofilter is very picky with dates. (I still say an OLAP cube is best )
    ..... Ok I give up.....

    How Bob?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •