Quote from nitro:
First, to readers that don't know, in VB the first day of the week is Sunday = 7, Monday = 1, Tuesday = 2, etc.
The first part of the if clearly works. If the first day of the week is Sunday = 7, then add 19 days + 1 day, and you get the third Friday which would always be the 20th. That always works.
The second part of the if is more complex. If the first of the month is any other day than Sunday, add 1 day to 14 + (6 - DayOfWeekOfFirstDayOfMonth), and that in theory is the third Friday. Doesn't works this month, Feb 2007: 14 + (6 - 4) + 1 = 17th (Unless Thursday is the 5th day in VB?)
Interestingly enough, you can turn this calculation to get the weekofmonth using a little modular arithmetic once you get it working...
nitro
Nitro
Actually Sunday = 1, Monday = 2 etc. By default anyway. So I have assumed Friday = 6.
I have tidied my routine up a little bit. If the first day of the month is after Friday (i.. Saturday, because Sunday is considered BEFORE Friday), I add 3 weeks instead of 2.
Dim ExtraDays As Integer
If Weekday(DateSerial(Year(Now), Month(Now), 1)) > 5 Then
ExtraDays = 21
Else
ExtraDays = 14
End If
Debug.Print DateAdd("d", ExtraDays + (6 - Weekday(DateSerial(Year(Now), Month(Now), 1))), DateSerial(Year(Now), Month(Now), 1))
