XLA routines: EE_NthWeekdayOfMonth
EE_NthWeekdayOfMonth returns the nth weekday of the month that a date is in.
- so you could use this function to find the 3rd wednesday in the month (an IMM date for example), or the 2nd Friday... whatever you need
Function EE_NthWeekdayOfMonth(dt As Date, nthWkday As Integer, wkday As EE_Weekday) As Date 'Takes a date, n, and the day of the week (mon, tue, wed) and returns the 2nd tuesday (for example) of the month. Dim x As Integer Dim dtLoop As Date 'http://excelexperts.com/xla-routines-eeNthWeekdayOfMonth for updates on this function For dtLoop = EE_FirstDayOfMonth(dt) To EE_LastDayOfMonth(dt) If Weekday(dtLoop) = wkday Then x = x + 1 If x = nthWkday Then EE_NthWeekdayOfMonth = dtLoop Exit Function End If End If Next dtLoop End Function
»
- Nick's blog
- Login or register to post comments
- 2838 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago