VBA code for calculating friday occuring prior to a random datespecified

  • Thread starter Thread starter enpaksh
  • Start date Start date
E

enpaksh

I need to calculate the date on a friday occuring before a random date
mentioned. eg.- if the date is 11/29/2007, or even 11/25/2007, i need
a way to get 11/23/2007 as the answer. can anyone help me with the
logic?
Thanks a lot!
 
I need to calculate the date on a friday occuring before a random date
mentioned. eg.- if the date is 11/29/2007, or even 11/25/2007, i need
a way to get 11/23/2007 as the answer. can anyone help me with the
logic?
Thanks a lot!

' Determines the previous instance of the given day of the week
' dow = the day of week(see Weekday)
' d = the date upon which to find the previous instance
Public Function PrevDayOfWeek(d As Date, dow As Integer) As Date
If Weekday(d) > dow Then
PrevDayOfWeek = d - (Weekday(d) - dow)
Else
PrevDayOfWeek = d - Weekday(d) - (7 - dow)
End If
End Function
 
Back
Top