Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function basMnthWrkDay(Optional dtIn As Variant, Optional StrtOrEnd As Variant) As Date
Dim intDOW As Integer
Dim dtMyDt As Date
Dim dtDOMnth As Date
Dim blnSOE As Boolean
'Check for a date input. If none, assumme todays's date
If (IsMissing(dtIn)) Then
dtMyDt = Date
Else
dtMyDt = dtIn
End If
'Check wheather to return the start date or the end date _
Note: NO entry will be the start (default). ANY entry will be End
If (IsMissing(StrtOrEnd)) Then
blnSOE = True
Else
blnSOE = False
End If
If (blnSOE = False) Then
'calc next last workday of month
dtDOMnth = DateSerial(Year(dtMyDt), Month(dtMyDt) + 1, 0)
intDOW = Weekday(dtDOMnth)
If intDOW = 1 Then
basMnthWrkDay = DateAdd("d", -2, dtDOMnth)
ElseIf intDOW = 7 Then
basMnthWrkDay = DateAdd("d", -1, dtDOMnth)
End If
Else
'calc next first work day of month
dtDOMnth = DateSerial(Year(dtMyDt), Month(dtMyDt), 1)
intDOW = Weekday(dtDOMnth)
If intDOW = 1 Then
basMnthWrkDay = DateAdd("d", 1, dtDOMnth)
ElseIf intDOW = 7 Then
basMnthWrkDay = DateAdd("d", 2, dtDOMnth)
End If
End If
End Function
[code]
MichaelRed
m.red@att.net
Searching for employment in all the wrong places
Public Function basStDtEndDt(Optional dtIn As Variant, Optional StOrEnd As Variant) As Date
'Michael Red 2/10/2004 Tek-Tips thread222-771062 _
Adapted from Pseudo Code posted by rdroske
Dim rtnWkDay As Date 'Added Declarations as 'Standard' of good practice
Dim MyDt As Date
Dim MyRtn As String
Dim MyIntvl As Integer
Dim MyWkDay As Integer
If (IsMissing(dtIn)) Then 'Added Checking of Input
MyDt = Date
End If
If (IsDate(dtIn)) Then
MyDt = dtIn
Else
MyDt = Date
End If
If (Not IsMissing(StOrEnd)) Then
MyRtn = Left(StOrEnd, 1)
End If
If (MyRtn <> "E") Then
MyRtn = "S"
End If
If (MyRtn = "S") Then 'Return Start
rtnWkDay = MyDt - Day(Date) + 1
MyIntvl = 1
MyWkDay = vbMonday
Else
rtnWkDay = DateSerial(Year(MyDt), Month(MyDt) + 1, 0)
MyIntvl = -1
MyWkDay = vbFriday
End If
'Correct To proper "WorkDay"
While (Weekday(rtnWkDay) <> MyWkDay)
rtnWkDay = rtnWkDay + MyIntvl
Wend
basStDtEndDt = rtnWkDay
End Function