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
- 2876 reads
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago