Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 5 of 5

Thread: code to return a first wednesday of a month

  1. #1
    Join Date
    19th August 2005
    Posts
    2

    code to return a first wednesday of a month

    hi guys

    can any1 help me out with finding a code to check if todays is the first wednesday (or any other day) of the month?

    ps. month is not specified/inputed, so it has to figure out from the current date that if today is wednesday and if it is the first wednesday!

    thanks

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    28th January 2003
    Location
    Solihull - England
    Posts
    8,678

    Re: code to return a first wednesday of a month

    something like this UDF would work

    VB:
    Function FirstWhatDay(StartDate As Date, MyWeekday As Integer) 
         'Will return the date of the first occurance of the Weekday specified
         'after the Start Date
         
        Do Until Weekday(StartDate, vbMonday) = MyWeekday 
            StartDate = StartDate + 1 
        Loop 
        FirstWhatDay = StartDate 
         
    End Function 
    
    
    Last edited by Will Riley; August 25th, 2005 at 20:21.
    Kind Regards, Will Riley

    Web Presence:
    LinkedIn: Will Riley

  3. #3
    Join Date
    18th November 2004
    Location
    God's Own Country
    Posts
    4,353

    Re: code to return a first wednesday of a month

    Hi,

    Try,

    =(DATE(YEAR(TODAY()),MONTH(TODAY()),1)-WEEKDAY(DATE(YEAR(TODAY()),MONTH(TODAY()),1),3))+2

    will return the first Wednesday of the month

    HTH

  4. #4
    Join Date
    18th November 2004
    Location
    God's Own Country
    Posts
    4,353

    Re: code to return a first wednesday of a month

    Small correction in the formula. Here is a revised one.

    Define SDATE

    =DATE(YEAR(TODAY()),MONTH(TODAY()),1)

    To return first Wednesday

    =IF(MONTH((SDATE-WEEKDAY(SDATE,1))+4)<>MONTH(SDATE),((SDATE+7-WEEKDAY(SDATE+7,1))+4),(SDATE-WEEKDAY(SDATE,1))+4)

    HTH

  5. #5
    Join Date
    17th May 2005
    Location
    St. Louis, MO
    Posts
    85

    Re: code to return a first wednesday of a month

    The formula will test today's date to see if it is the First Wednesday. Replace the text strings with whatever you want, including two double-quotation marks for a blank cell.

    If you want to test for a different day of the week, change the 4 to some other number... Sunday = 1, Monday = 2, etc.

    VB:
    =If(WEEKDAY(TODAY(),1)=4,If(DAY(TODAY())<=7,"First Wednesday","Wednesday, But Not First"),"Not Wednesday") 
    
    
    Alex.

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. VBA Code to Return First Sunday of the Month
    By Justice23 in forum EXCEL HELP
    Replies: 5
    Last Post: November 16th, 2010, 07:47
  2. Increase Date By 1 Month & Return Month Name
    By Macropheliac in forum EXCEL HELP
    Replies: 6
    Last Post: October 29th, 2006, 09:08
  3. Return First Specified Day of Month
    By abbeville in forum EXCEL HELP
    Replies: 3
    Last Post: November 11th, 2005, 17:50
  4. Return Last Day of Month
    By Dave Hawley in forum Excel FAQ
    Replies: 0
    Last Post: September 30th, 2005, 16:36
  5. Return value for specified day within a month
    By WendyB in forum EXCEL HELP
    Replies: 3
    Last Post: November 11th, 2004, 23:13

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
  •  
porno