+ Reply to Thread
Results 1 to 8 of 8

Determine financial year end for a date

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Determine financial year end for a date

    Want to create a VBA function that can return me the financial year end date of any date when I only have the month of financial year as a parameter.
    Financial_Yearend(dDate As Date, nMonth As Integer) As Date
    For instance: If financial year ends February then a financial year runs from 1/3/???? to 28/2/???? and for a leap year it's 1/3/???? to 29/2/????.

    So if I enter any date between 1/3/2006 and 28/2/2007, say 5/12/2006 (dd/mm/yyyy format) and the nMonth parameter as 2 (February) the function must return date as 28/2/2007 (dd/mm/yyyy format). For leap year any date between 1/3/2007 and 29/2/2008 will return 29/2/2008.

    I have no idea how to attack this. Any ideas appreciated.

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Determine financial year end for a date

    Financial_Yearend(dDate As Date, nMonth As Integer) As Date
    Dim Ye as Date
    Ye = Date(year(dDate), nmonth +1, 1) -1
    If (Ye < dDate) then
         Financial_Yearend = Date(year(Ye)+1,month(Ye),Day(Ye))
    Else
         Financial_Yearend = Ye
    End if
    End Function
    Written without Excel to hand so there may be some errors
    If someone has helped you then please add to their Reputation

  3. #3
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Determine financial year end for a date

    pjwhitfield:

    Should the date function you used be dateserial function (if I use date as you had it it gives an error)? If so then it doesn't work. See YE returned below. It's not handling the leap year correctly.
    Date: 01/01/2007 FY: 28/02/2007 - correct
    Date: 30/01/2007 FY: 28/02/2007 - correct
    Date: 28/02/2007 FY: 28/02/2007 - correct
    Date: 29/03/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 27/04/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 26/05/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 24/06/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 23/07/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 21/08/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 19/09/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 18/10/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 16/11/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 15/12/2007 FY: 28/02/2008 - this should be 29/02/2008
    Date: 13/01/2008 FY: 29/02/2008 - here it's correct
    Date: 11/02/2008 FY: 29/02/2008 - here it's correct
    Date: 11/03/2008 FY: 01/03/2009 - this should be 28/02/2009
    Date: 09/04/2008 FY: 01/03/2009 - this should be 28/02/2009
    Date: 08/05/2008 FY: 01/03/2009 - this should be 28/02/2009
    Date: 06/06/2008 FY: 01/03/2009 - this should be 28/02/2009
    Date: 05/07/2008 FY: 01/03/2009 - this should be 28/02/2009
    Last edited by Bezzie; 11-21-2014 at 12:55 AM.

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Determine financial year end for a date

    Schoolboy error on my behalf!

    To get the last day of month I was setting the date to the 1st of the following month and deducting a day.....which works fine however I was then deciding if it needed to be the year after and adding a year on rather than doing it the other way round!

    Function Financial_Yearend(dDate As Date, nMonth As Integer) As Date
    Dim Ye As Date
    Ye = DateSerial(Year(dDate), nMonth + 1, 1)
    If (Ye < dDate) Then
         Financial_Yearend = DateSerial(Year(Ye) + 1, Month(Ye), Day(Ye))
    Else
         Financial_Yearend = Ye
    End If
         Financial_Yearend = Financial_Yearend - 1
    End Function

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Determine financial year end for a date

    How about just a formula?

    Row\Col
    H
    I
    J
    K
    1
    Date
    Month
    EoFY
    2
    02/28/2014
    2
    02/28/2014
    J2: =EOMONTH(DATE(YEAR(H2) + (MONTH(H2) > I2), I2, 1), 0)
    3
    03/01/2014
    2
    02/28/2015
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Determine financial year end for a date

    shg:

    Your example works like a charm in Excel cell but when using it in VBA it doesn't want to accept the function. Gives an error. I added Application.WorksheetFunction in front and changed the cell references to the parameter variables but can't get it to accept the function.
    Financial_YearEnd = Application.WorksheetFunction.EOMONTH(DATE( YEAR(ddate) + (MONTH(ddate) > nmonth), nmonth, 1), 0)
    YEAR is highlighted and error message is "Compile error: Expected: )"

    Working with dates is a real pain in the @$$

  7. #7
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Determine financial year end for a date

    Thanks. It's working now from VBA.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Determine financial year end for a date

    Another way:

    Function EoFY(tDate As Date, iMon As Long) As Date
      EoFY = DateSerial(Year(tDate) - (Month(tDate) > iMon), iMon + 1, 0)
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] To calculate last date of a financial year
    By aparunkumar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-26-2013, 02:38 AM
  2. Input a year to determine the start date for 4-4-5 Calendar Year.
    By mak1176 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-25-2013, 10:34 AM
  3. Determine if date is before end of fiscal year of previous year
    By ccarver in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-13-2010, 11:53 AM
  4. Last date of Financial year
    By vandanavai in forum Excel General
    Replies: 2
    Last Post: 08-30-2009, 08:53 AM
  5. Totalling up a Financial Year to date
    By Voodoodan in forum Excel General
    Replies: 3
    Last Post: 03-21-2005, 11:19 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1