1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Calculate xth day of month

Discussion in 'Business Applications' started by Pedro15, Apr 14, 2015.

Thread Status:
Not open for further replies.
Advertisement
  1. Pedro15

    Pedro15 Thread Starter

    Joined:
    Oct 5, 2008
    Messages:
    386

    Attached Files:

  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    I did not look at your files, just want to give you this.

    I found this code a long time ago and have been using it since.

    This formula will return the date of any day of the week you enter

    Code:
    ' We can generalize this to holidays that are defined as the Nth Day of some month,
    ' such as Martin Luther King's birthday, celebrated on the 3rd Monday of January.
    ' The following function will return the Nth DayOfWeek for a given month and year:
    'SYntax NDOW:
    '   y = Year
    '   M = Month
    '   N = Nth day of M month
    '   DOW = Day of the week:  1 = Sunday, 2= Monday, etc.
    Public Function NDow(Y As Integer, M As Integer, N As Integer, DOW As Integer) As Date
        NDow = DateSerial(Y, M, (8 - WeekDay(DateSerial(Y, M, 1), (DOW + 1) Mod 8)) + ((N - 1) * 7))
    End Function
    
    The comments in the code are form the original code and should explain itsself
     
  3. Pedro15

    Pedro15 Thread Starter

    Joined:
    Oct 5, 2008
    Messages:
    386
    Hans,
    Thanks for that though I am not that much savvy with macros so will try and struggle though it tomorrow.
    In the meantime if someone can explain where I have gone wrong with my attempt it would be appreciated

    Pedro
     
  4. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    I'll take a look and see if I can find it.
    I will also implement the code I posted to see if it helps you
     
  5. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,597
    First Name:
    Hans
    I placed the code in the file and made some changes to the formulas and sheet
    See attached file
     

    Attached Files:

  6. Pedro15

    Pedro15 Thread Starter

    Joined:
    Oct 5, 2008
    Messages:
    386
    Thanks Hans thats brilliant.
    Much appreciated.

    Pedro
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1146609

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice