+ Reply to Thread
Results 1 to 5 of 5

Generating List of Week Working days and Identifying Holidays

  1. #1
    Valued Forum Contributor ron2k_1's Avatar
    Join Date
    09-30-2009
    Location
    Not the USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    606

    Generating List of Week Working days and Identifying Holidays

    From another thread I got this formula placed on B5:
    =NETWORKDAYS(EOMONTH(B4,-1)+1,EOMONTH(B4,0),Holidays)

    his generates the number of working days for that month (regardless of the date on B4) that exclude Holidays listed under the range "Holidays".

    I also got this code (Credits to XXXX)

    Please Login or Register  to view this content.
    That will generate the number of week days. However, this is my issue, and those that understand the code will notice, that regardless of the date I input on B4, say May 5, 2009, but as I enter something on column C, it will change my B4 date to Oct 28 and give me all week days for October only. I will then change B4 to say June 5, 2009, and delete the dates generated by the code and input something on Column c again, and again, it will change B4 to Oct 28,2009.

    Any ideas on how tell the code not to change my date, and generate the week days for the month of the date on B4 instead. And then naturally, if there is a holiday in that range generated, it will list the day as well (i.e. it will not be excluded). This is fine, however, can anybody help me to put beside the holiday date (listed under range Holiday) on the range generated by code the word "Holiday", and beside all others "Working Day"?

    Thank you.

    Ron
    Excel2003

    EDIT

    I have deleted this line:
    .Range("B4").Value = Date

    Now it doesn't change the date on B4, but the list of week days generated is still for October!! :-(
    Last edited by ron2k_1; 10-29-2009 at 02:25 PM. Reason: Solved: Thank you, thank you DonkeyOte

  2. #2
    Valued Forum Contributor ron2k_1's Avatar
    Join Date
    09-30-2009
    Location
    Not the USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    606

    Re: Generating List of Week Working days and Identifying Holidays

    Update:

    I changed the line (with the help of an online friend):
    Please Login or Register  to view this content.
    Into this:
    Please Login or Register  to view this content.
    However, he may not seem to figure out how identify each day on the list generated as "Working Day" or "Holiday" (This words to be placed beside each day. The range of holidays, I have named "Holidays.

    Anybody, please..

    Ron

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

    Re: Generating List of Week Working days and Identifying Holidays

    I guess I / we're confused as to what it is you want to do...

    I'm guessing you want to use VBA to generate for you the working days of the month specified by date in B4 ?
    And presumably you want to do this without using the NETWORKDAYS function (ie avoiding Analysis ToolPak), correct ?

    Rather than use a Worksheet_Change event why not use a UDF - it will make it easier to use in other cells / sheets etc ?

    eg

    Please Login or Register  to view this content.
    The above, stored in a Module can be called from any cell along the lines of:

    =NWDAYSMONTH(B4,Holidays)

    If you still want to run as part of a Change event you can do of course you just to modify re: inputs.

  4. #4
    Valued Forum Contributor ron2k_1's Avatar
    Join Date
    09-30-2009
    Location
    Not the USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    606

    Re: Generating List of Week Working days and Identifying Holidays

    Wow, this is useful, thank you, it is always good to find additional ways to to generate this. Thank you, but I didn't have a problem with the EOMONTH function. As a matter of fact, after some thought eventually I realized that this worksheet function could have worked:
    =NETWORKDAYS(DATE(YEAR(B4),MONTH(B4),1),DATE(YEAR(B4),MONTH(B4)+1,0),Holidays)

    I'm not sure if NETWORKDAYS function needs the analysis toolpack installed...

    Anyways, as I explained the code that I found generates a list, starting from B7, of all week days within the month specified in B4. I was wondering whether we can insert and IF/VLOOKUP function in the code as well (as I did on my attachment), so that it looks in my list of holidays named "Holidays", and if it finds a holiday in that month return "Holiday" if not "Working Day".

    And one more thing, is it possible that the list of week days is generated right after changing B4, rather than typing something on colomn C.

    I noticed something on the code as well. Say I change B4 to some date in December. I type something on C4, I will then get my list of week days starting on B7. Say I change B4 now to something like Feb 2. It will then generate a list starting on B7, it will stop (I think) on Feb 28, but it will leave December 30, and 31st!!!! (Which was the previous list). We can prob tell the code to clear the range from, say, B7:B37 before it generates the list.

    I know you can do this. Do you have the time???

    Ron


    C4Attachment 56724
    Attached Files Attached Files

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

    Re: Generating List of Week Working days and Identifying Holidays

    Not really tested but perhaps replace your existing code with

    Please Login or Register  to view this content.

+ 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