+ Reply to Thread
Results 1 to 15 of 15

Count specific day between fixed dates, with user input controlling time frame, month/s

  1. #1
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Count specific day between fixed dates, with user input controlling time frame, month/s

    I would post a file but I cannot insert the excel file.

    Start Date End Date TOTAL DAYS END DATE MINUS START DATE SATURDAYS END DATE MINUS START DATE SAT in DATE RANGE SUNDAYS END DATE MINUS START DATE SUN in DATE RANGE WEEK DAYS ONLY WEEK DAYS IN DATE RANGE DATE RANGE (W14 and W15)"

    =IFERROR(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(G31&":"&F31)))={1,2,3,4,5,6,7})),"0") =IFERROR(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(G31&":"&F31)))=7)),"0") =IFERROR(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(G31&":"&F31)))=1)),"0") =IFERROR(SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(G31&":"&F31)))={2,3,4,5,6})),"0") =IF(OR($G31<$W$14,$F31>$W$15),0,ABS(NETWORKDAYS(MIN($W$15,$G31),MAX($W$14,$F31)))) =IF(OR($G31<$W$14,$F31>$W$15),0,ABS(NETWORKDAYS(MIN($W$15,$G31),MAX($W$14,$F31)))) =IF(OR($G31<$W$14,$F31>$W$15),0,ABS(NETWORKDAYS(MIN($W$15,$G31),MAX($W$14,$F31)))) =IF(OR($G31<$W$14,$F31>$W$15),0,ABS(NETWORKDAYS(MIN($W$15,$G31),MAX($W$14,$F31))))

    I have trouble for the results for SAT in Date Range and Sun in Date Range

    Thank you, dflak

    I attached the xlsm file and when I try to open it is says it is a php file. I changed the extension from php to xlsm and it opens in exel.
    Attached Files Attached Files
    Last edited by Joe Bob Crain; 02-03-2017 at 05:24 PM. Reason: Adding Spread Sheet and file extension

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    It looks like you may be going about this the hard way first, take a look at WORKDAYS or NETWORKDAYS. If that doesn't get it maybe one of the formulas in this reference would help http://www.cpearson.com/excel/DateTimeWS.htm.

    Here are the instructions on how to attach a workbook.

    To Attach a File:

    1. Scroll down to the window below your post Additional Options
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    Thank you, dflak

    I attached the xlsm file and when I try to open it is says it is a php file. I changed the extension from php to xlsm and it opens in exel.
    Attached Files Attached Files

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    To fix the PHP problem (I assume you are using IE). Got to Tools -> Compatibility View Settings and add this site to the list. You might have done that in the past, but a lot of people (self included) got it turned off somehow. Me suspects a Microsoft update to IE as the culprit.

    I'll take a look at the file next week. It's getting close to TGIF here

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    Let me ask about an example. For row 143, the start date is 11/14/2016 and the end date is 12/5/2016. You want to know how many Saturdays and Sundays happen between these dates. I'm confused by the comments and the references to the other dates.

    I think walking me through an example or two (a "happy case" and one with an exception) will help me understand what you are looking for better.

  6. #6
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    The date for start to end is 11/14/16 to 12/5/16 and I want to know the Saturdays and Sundays between those date during the selected time frame of cells W14 and W15; 12/1/16 thru 12/31/16.

    The formula for N143 thru N155 works for the weekdays during the selected time frame W14 thru W15 looking at the Start an End Date F143:F155 and G143:155

    =IF(OR($G17<$W$14,$F17>$W$15),0,ABS(NETWORKDAYS(MIN($W$15,$G17),MAX($W$14,$F17)))), (Credit to C. Pearson for providing examples)

    The problem is I cannot get the correct number of Sat or Sun in the selected (date range, (W14, W15)), from the (start and end dates, (F143:F155, G143:155)).

    Thank you for your help dflak

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    So, the dates in the cells is 11/14/16 to 12/5/16. Elsewhere you have a range 12/1/16 to 12/31/16. The range you want to consider is the intersection of these two ranges so you want to know the number of Saturdays and Sundays between 12/1/16 and 12/5/16. Is this correct?

    Is the purpose of this to get working days? Or do you need to know the number of Saturdays and Sundays for some other purpose and do you want to account for holidays?

  8. #8
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    dflak,

    The answer is yes, count the Sat and Sun in separate columns, (minus the Holidays), between the intersection dates.

    I already have the working days column formula and it works.

    Thank you

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    Normally I am a fan of using formulas over VB code, and I probably could do this with a formula, but it would get ugly fast. So if you are willing to accept a VB solution, here it is.

    The function, NumDays, takes as its arguments Start Range, End Range, Start Date, End Date, Day of the Week.

    So Start Range is W14, End Range is W15, Start Date is Column F, End Date is Column G and Day of Week is either "Sat" or "Sun."
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    Thank you dflak for your knowledge, time, and effort.

    P.S. How do I closed the thread; since you have answered my question?

  11. #11
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    At the very top of the thread select Thread Tools from the menu link and mark the thread as SOLVED.

  12. #12
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    dflak,
    I assume the VBA was correct when i used in my spread sheet it calculates incorrectly. It work okay by not counting Saturdays and Sundays before the range Dates.
    But but counts Saturday and Sundays past the end of the Range Date. I have enclosed the spread sheet with your VBA.

    I did not know if I should start with a new post or ask and attach in my Solved post?

  13. #13
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    I'll take a look at this tomorrow.

  14. #14
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    I think found the offending line of code. Good catch, good write-up and thanks for highlighting the exceptions. All of this made debugging a lot easier.

  15. #15
    Registered User
    Join Date
    03-24-2006
    Posts
    9

    Re: Count specific day between fixed dates, with user input controlling time frame, month/

    dflak,
    Checked out the corrections. And it Works great.
    Thank you again for your time, effort, and knowledge.

+ 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. Number of Samples in a Month time frame
    By lchee in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-03-2016, 03:48 AM
  2. Replies: 2
    Last Post: 04-15-2015, 03:58 PM
  3. Replies: 2
    Last Post: 12-17-2013, 06:30 AM
  4. [SOLVED] Controlling dates that overlap from month to month
    By dontaylor in forum Excel General
    Replies: 2
    Last Post: 10-22-2013, 11:06 AM
  5. Excel 2007 Horizontal Bar Chart with fixed time frame
    By chartnovice in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 09-19-2012, 01:16 PM
  6. Loan Calculator with Terms based on Fixed Payment not a fixed time frame.
    By cc4digital in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-03-2012, 04:49 AM
  7. Count specific dates in cell range for current month
    By rboggio1 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-22-2009, 10:21 PM

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