+ Reply to Thread
Results 1 to 12 of 12

Macro to Return Net Work Days by Fiscal Year

  1. #1
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Macro to Return Net Work Days by Fiscal Year

    Hello,

    I want to create Macro that calculates Net Work Days between two dates and that also excludes holidays, but instead of difference displayed in a lump sum, I want the correct Net Work Days (excluding Holidays as well) to be displayed under its correct Federal Fiscal Year Row Title. I want the macro to use the list (holidaylist) I created in the workbook attached “TresExample” to be used to exclude the correct holidays from the correct Federal Fiscal Year.

    In the example I provide in the attached workbook I am only using 10 records to simplify the example, but realistically I could have up to 20,0000 records.

    In case you don’t know the Federal Fiscal Years are the following:

    FY2011 10/1/2010 9/30/2011
    FY2012 10/1/2011 9/30/2012
    FY2013 10/1/2012 9/30/2013
    FY2014 10/1/2013 9/30/2014
    FY2015 10/1/2014 9/30/2015
    FY2016 10/1/2015 9/30/2016
    FY2017 10/1/2016 9/30/2017
    FY2018 10/1/2017 9/30/2018
    FY2019 10/1/2018 9/30/2019
    FY2020 10/1/2019 9/30/2020


    In the workbook attached to this post I have the following worksheets:
    1. Holidaylist
    2. Data Before Macro is Executed
    3. Data After Macro is Executed

    If you need me to clarify something just let me know.

    - BC
    Attached Files Attached Files
    Last edited by boldcode; 02-07-2013 at 08:31 PM. Reason: Solved

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Macro to Return Net Work Days by Fiscal Year

    Are you interested in a formula approach at all?

    If so you could put this formula in N2

    =MAX(0,NETWORKDAYS(MAX($K2,DATE(RIGHT(N$1,4)-1,10,1)),MIN($L2,DATE(RIGHT(N$1,4),9,30)),holidaylist!$A$2:$A$104))

    custom format N2 as 0;; and then copy across and down
    Audere est facere

  3. #3
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Macro to Return Net Work Days by Fiscal Year

    I like what you came up and it works, but if I could some how put this formula in a macro so I don't have to copy across and down manually for 20,000 records that would be awesome.

    I seen this done before where a formula is drop in a Macro; if you could help I would greatly appreciate it.

  4. #4
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Macro to Return Net Work Days by Fiscal Year

    Hey daddylonglegs,

    I almost have it in code, I just don't know how to make it copy across. Below is the the code that I am using which works going down, but does not copy across just yet.

    Code:

    Please Login or Register  to view this content.
    I could use your help.

    thanks again

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Macro to Return Net Work Days by Fiscal Year

    Easiest way:
    Define a Name, say, MyNet, and copy DDL's formula into the refers to box. Then in N2 type "=MyNet"; copy down and across.
    Ben Van Johnson

  6. #6
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Macro to Return Net Work Days by Fiscal Year

    protonLeah,

    You kind of lost me with your suggestion. I am personally not that good with VBA. I just wanted to added some code to the code I struggled to create so when I click my macro it copies across and down.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Macro to Return Net Work Days by Fiscal Year

    Please Login or Register  to view this content.

    Regards, TMS
    Last edited by TMS; 02-07-2013 at 08:31 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Macro to Return Net Work Days by Fiscal Year

    VBA is not needed. Ribbon: Formulas ---> Define name
    in the New Name dialog, type in your desired name for the formula, then in the "refers to box" paste in the formula in post #2. Then in N2 just type "=" with whatever name you chose for the formula.

  9. #9
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Macro to Return Net Work Days by Fiscal Year

    protonLeah,

    Thank you for the explanation, now I see what you are saying.

  10. #10
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Macro to Return Net Work Days by Fiscal Year

    TMShucks,

    I just tried your code and it works exactly the way I envision it. Thank you!

    - BC

  11. #11
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Macro to Return Net Work Days by Fiscal Year

    daddylonglegs,

    I just wanted to thank you for the formula you provided me with.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Macro to Return Net Work Days by Fiscal Year

    You're welcome.

    Please note I have edited the code to include the formatting of the cells.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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