Public Function LastNthDayOfTheMonth( _
intMonth As Integer, _
intYear As Integer, _
intDayOfWeek As VbDayOfWeek) As Date
'
' arnelgp
' 23-December-2017
'
' Translated from:
'
' 101 Ready-to-Use Excel Formulas (c)2014
' Michael Alexander
' Dick Kusleika
'
' Returns the last day in which a particular Day of Week falls
'
' Parameters:
' intMonth Integer. the month portion (1-12).
' intYear Integer. Year portions (eg: 2017)
' intDayOfWeek Integer. Example vbMonday, vbTuesday, etc.
'
' Example:
' What date does the Last Sunday of January 2017 falls?
' =LastNthDayOfTheMonth(1, 2017, vbSunday)
'
' How about the Last Tuesday of March 2016?
' =LastNthDayOfTheMonth(3, 2016, vbTuesday)
'
' Returns: Date
'
LastNthDayOfTheMonth = DateSerial(intYear, intMonth + 1, 1) - _
Weekday(DateSerial(intYear, intMonth + 1, 8 - intDayOfWeek))
End Function