Ozgrid Excel Help & Best Practices Forums

Excel Training / Excel Dashboards Reports

# Thread: code to return a first wednesday of a month

1. I agreed to these rules
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. ## 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.

3. Super Moderator
Join Date
18th November 2004
Location
God's Own Country
Posts
4,682

## 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. Super Moderator
Join Date
18th November 2004
Location
God's Own Country
Posts
4,682

## 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. Member
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

##### Users Browsing this Thread

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

#### 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