Function lwim(d As Date, wd As Integer, Optional i As Integer = 1) As Date
'Lwim [Last weekday in month] returns last but (i-1)-th weekday wd of month d:
'd - date of last day of desired month but can be any day in desired month
'wd - weekday: 1-Sunday, 2-Monday, ..., 7-Saturday
'i - 1 will return last, 2 last but one, etc.
'Reverse("moc.LiborPlus.www") V0.20 PB 12-Sep-2009
Dim dr As Date, wd0 As Integer
dr = DateSerial(Year(d), Month(d) + 1, 0) 'Ensure to start with last day of month
wd0 = wd Mod 7 'Saturday = 0
lwim = Int((dr + ((dr Mod 7) < wd0) * wd0 - (i - 1) * 7 + 6) / 7) * 7 + wd0 - 7