Hi noiseash
Try this custom function. It will return a number between 0 and 4 based on the day and date you specify.
To use the custum function, Go to Tools>Macro>Visual Basic Editor(Alt+F11) and go to Insert>Module and paste in the code below. Then come back to Excel proper and use it like;
=nthDayOfMonth("Fri",TODAY())
You can nest it with an IF Function and the CHOOSE function to tell excel what action it should take. E.g;
=IF(nthDayOfMonth("Thu",TODAY())=0,"",CHOOSE(nthDayOfMonth("THU",TODAY()),"First","Second","Third","Fourth"))VB:Function nthDayOfMonth(sWeekDay As String, dDate As Date) Dim lDay As Long Dim lDayCount As Long Dim lWeekDay As Long Select Case UCase(sWeekDay) Case Is = "MON" lWeekDay = 2 Case Is = "TUE" lWeekDay = 3 Case Is = "WED" lWeekDay = 4 Case Is = "THU" lWeekDay = 5 Case Is = "FRI" lWeekDay = 6 Case Is = "SAT" lWeekDay = 7 Case Is = "SUN" lWeekDay = 1 End Select On Error Resume Next For lDay = 1 To Day(dDate) If WeekDay(DateSerial(Year(dDate), Month(dDate), lDay)) = lWeekDay Then lDayCount = lDayCount + 1 End If Next lDay nthDayOfMonth = lDayCount End Function


Reply With Quote
Bookmarks