Sathish KV
Active Member
Hi,
The below UDFs (user defined functions) can be used to find week number of the month, first day of the month and the last day of the month with a date
The below UDFs (user defined functions) can be used to find week number of the month, first day of the month and the last day of the month with a date
Code:
Option Explicit
Function FINDWEEK(dDate1 As Date) As String
'Formula Example =FINDWEEK(Date)
Dim dDate2 As String
Dim wWeek As Integer
dDate2 = DateSerial(Year(dDate1), Month(dDate1), 1)
wWeek = DateDiff("ww", dDate2, dDate1, vbSunday, vbUseSystem) + 1
FINDWEEK = "Week " & wWeek
End Function
'---------------------------------------------
Function FIRSTDAY(Optional dDate1 As Date = 0) As Date
'Formula Example =FIRSTDAY(Date)
' Returns the first day in the specified month.
If dDate1 = 0 Then
' Did the caller pass in a date? If not, use
' the current date.
dDate1 = VBA.Date
End If
FIRSTDAY = DateSerial(Year(dDate1), Month(dDate1), 1)
End Function
'---------------------------------------
Function LASTDAY(Optional dDate1 As Date = 0) As Date
'Formula Example =LASTDAY(Date)
' Returns the last day in the specified month.
If dDate1 = 0 Then
' Did the caller pass in a date? If not, use
' the current date.
dDate1 = VBA.Date
End If
LASTDAY = DateSerial(Year(dDate1), Month(dDate1) + 1, 0)
End Function