+ Reply to Thread
Results 1 to 4 of 4

Business/Workdays

  1. #1
    Registered User
    Join Date
    06-04-2010
    Location
    Bolton, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Business/Workdays

    Hi all,

    I'm looking for some help regarding calculating business days in VBA. I have a function which is great, however I'm automating the input of the said formula and I can find no way of calling a user defined function in a sub routine. I've started with this;

    Please Login or Register  to view this content.
    It works great on some date ranges, but on others I can't understand where the value is coming from. For example;

    Start Date = 16/10/10
    End Date = 22/10/10

    Business Days Function = 4 days
    The above coding = 4 days

    But then I get this;

    Start Date = 17/10/10
    End Date = 25/10/10

    Business Days Function = 5 days
    The above coding = 7 days

    Clearly there is something missing from my code. Any help would be much appreciated.

    Thanks,
    Lee
    Last edited by lee2k60; 10-28-2010 at 10:19 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Business/Workdays

    Assuming you're looking to avoid dependence on Analysis ToolPak functionality (which is why you're not just using WORKDAY and NETWORKDAYS etc) then:

    Please Login or Register  to view this content.
    technically you don't need F & G to calc C (as illustrated) but left in nonetheless
    Last edited by DonkeyOte; 10-28-2010 at 09:33 AM. Reason: typo in sheet reference - sheet1 rather than 13

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Business/Workdays

    Hi Lee,

    You are not deducting the 2 weekend days when updating the "C" & lx cell with the correct business days.

    Create a new variable lWe as Long
    Set this to 2 in the following code and deduct the lWe value from the Vusiness days calc and reset it to zero before the next iteration.

    Please Login or Register  to view this content.
    But why are you re-inventing the wheel? Excel already gives you the NETWORKDAYS() function to do exactly this. You don't need a macro, just use

    Please Login or Register  to view this content.
    and copy it down your range. If you really want to use a macro then use the
    Application.WorksheetFunction.NetworkDays syntax

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    06-04-2010
    Location
    Bolton, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Business/Workdays

    Thanks Richard & DonkeyOte.

    All sorted now. Really appreciate your input.

    Cheers,
    Lee

+ 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