+ Reply to Thread
Results 1 to 9 of 9

date functions

  1. #1
    Registered User
    Join Date
    03-13-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    2

    date functions

    I need a function or combo of functions that will give me the date of a given day in a month.

    Like if I want the first Saturday or the fourth Monday, how do I ask Excel to give me that date?

    Oh, I don't do macros, just never learned how. So I greatly prefer to find the date with some sort of easily coded function.

    Any help is greatly appreciated. Thanks

  2. #2
    Forum Contributor
    Join Date
    03-12-2009
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 365
    Posts
    236

    Re: date functions

    I was able to come up with three methods, one of which is a simple user-defined function. Hopefully you will be able to see how each works. I can't test directly if this will work in Excel 2003 for you, but I did save it in the 97-2003 format from 2007.
    Attached Files Attached Files
    If you can't figure out how a formula works, try stepping through it using "Evaluate Formula" in the Formula Auditing menu item in the tools menu!

    If you want to see where your code went wrong, try stepping through it by clicking in the code and pressing F8 and watch as the magic happens!


    If you are happy with any of the results, please add to the contributor's reputation by clicking the star icon.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: date functions

    If you want to try a UDF

    Please Login or Register  to view this content.
    1/. Press alt+f11 to open the VBA Editor
    2/. In the editor ..... Insert>Module
    3/. Paste all the code in the new module
    4/. Close and return to Excel
    5/. In any cell

    Please Login or Register  to view this content.
    The order is Year (eg 2010), Month (1 to 12), Day (1 to 7 , Sun = 1), Reqd rank (1 to 5)
    there is no 4/5th occurence #ERROR# will be displayed.

    Omitting the last option will return the first day required

    Omitting the last 2 No. options will return the first Monday of the month
    Please Login or Register  to view this content.
    Returns the first Monday in January

    Format the cell to suit your date style as normal

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: date functions

    deke, what would your input look like? If you want a macro-free solution to find the third Tuesday of a month, how would want you specify that in your sheet? Can you upload a data sample of your sheet, with the structure and data types that you are currently using?

  5. #5
    Registered User
    Join Date
    03-13-2010
    Location
    Virginia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: date functions

    Everstriven - thanks. Just what I needed.

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

    Re: date functions

    FWIW, a formula based route which requires no helpers etc might be as follows

    (using everstrivin's sample file)

    =DATE($C$2,$D$2,1)+MOD($A$2-WEEKDAY(DATE($C$2,$D$2,1),2),7)+7*($B$2-1)

    Where:

    A2 holds the weekday number based on a Mon-Sun week (ie Mon is 1, Sun is 7)
    C2 holds Year
    D2 holds Month
    B2 holds Instance

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: date functions

    DonkeyOte
    FWIW, a formula based route which requires no helpers etc......
    It's weight in Gold might I suggest?

    I have a lot to learn before charging down the UDF route!

    Cheers
    Alistair

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

    Re: date functions

    Most if not all of the date formulae I post are based largely (if not entirely) upon posts made previously by daddylonglegs ... those I do cobble together myself he can normally streamline further (as is I'm sure the case here - if he sees it )

    Say hello to Fife for me... the years spent at St.Andrews were good ones

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: date functions

    Some good pubs there, a'what?

+ 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