+ Reply to Thread
Results 1 to 13 of 13

SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

  1. #1
    Registered User
    Join Date
    10-30-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Thumbs up SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Hi

    i am trying to calculate number of week days between 2 dates.

    In my Excel named 'Leave Detail', Cell H8 = Starting Date and Cell I8 = End Date i tried to save the return value in Cell J8 but it is populated with '#VALUE'.

    Sheets("Leave Detail").Range("J8").Value = Evaluate("SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT('Leave Detail'!H8:Leave Detail'!I8)),2)<6))")

    Please help.

  2. #2
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Hi Suchi508,

    Welcome to the forum.

    Try the below code:

    Please Login or Register  to view this content.
    Hope this helps.
    If solved kindly remember to mark Thread as solved.
    Click the small star icon at the bottom left of my post if this was useful.

  3. #3
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Just to add, Network days is a function that captures weekdays between any two sets of dates

  4. #4
    Registered User
    Join Date
    10-30-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    now J8 is populated with #NAME? .

    can you please confirm, for NETWORKDAYS() should i have 'AnalysisToolPak'? that is not installed in my machine not i am able to do so.
    Last edited by suchi0508; 10-30-2012 at 08:27 AM.

  5. #5
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Think you need to load the Analysis ToolPak add-in. Follow these steps:

    http://office.microsoft.com/en-gb/ex...005209190.aspx

  6. #6
    Registered User
    Join Date
    10-30-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    is there any other way to do this? because i tried to install it in the same way but didn't work. in addition to that , this excel may be used by other people as well, so its better if there is any other way to do this.

  7. #7
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Try the below modified version:

    Please Login or Register  to view this content.
    Hope this helps.

  8. #8
    Registered User
    Join Date
    10-30-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Thanks a lot. it works, but one more request, can you please let me know how to calculate the number of working day after deduction of the holiday,

    where holiday list is saved in another sheet, maned 'Accrual' and cell = B26 to B28

    when we calculate in Excel, then we can use something like, SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(H8&":"&I8)),2)<6),--ISNA(MATCH(ROW(INDIRECT(H8&":"&I8)),Accural!$B$26:Accural!$B$28,0))),"")

    but i am not sure how to do it on VBA.

  9. #9
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Are you able to upload a sample workbook?

  10. #10
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    In case you want to exclude any holidays this could be easily accomplished by using the =networkdays() function.

    Please Login or Register  to view this content.
    If you can play around with your excel setting to enable Analysis Tool Pack, you may get to have this work for you in a very simple manner.

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

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Quote Originally Posted by kbkumar View Post
    Please Login or Register  to view this content.
    This doesn't work, does it? if H8 is today (30th October) and I8 is 6 days later (5 November) I get a result of 1

    This formula will give you the same result as NETWORKDAYS

    =SUM(INT((WEEKDAY(H8-{2,3,4,5,6})+I8-H8)/7))

    and to take out holidays try

    =SUM(INT((WEEKDAY(H8-{2,3,4,5,6})+I8-H8)/7))-SUMPRODUCT((Accural!$B$26:$B$28>=H8)*(Accural!$B$26:$B$28<=I8)*(WEEKDAY(Accural!$B$26:$B$28,2)>6))
    Audere est facere

  12. #12
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    Hi Daddylonglegs: You are right. I tried some random historic dates and they seemed to be fine (wierd that it fails with your sample dates!). Could you please point why it fails as the logic seems to be ok?

  13. #13
    Registered User
    Join Date
    10-30-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: SUMPRODUCT used to calculate Number of weekdays, returns #VALUE in VBA

    i tried the same as Sheets("Leave Detail").Range("J8").Value = Evaluate("SUM(INT((WEEKDAY(H8-{2,3,4,5,6})+I8-H8)/7))-SUMPRODUCT((Accural!$B$26:$B$28>=H8)*(Accural!$B$26:$B$28<=I8)*(WEEKDAY(Accural!$B$26:$B$28,2)>6))")

    but J8 popupled with #VALUE!

    i am attaching Sample Excel for your reference. But please be aware from running the Macro. it's going to Infinite Loop.

    My Objective is to calculate Number of working Day per week after deducting the Leave and Holiday.
    Attached Files Attached Files
    Last edited by suchi0508; 10-30-2012 at 10:22 AM.

+ 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