DATEFIRST

There are 3 functions.
For instructions on how to add a function to a workbook refer to the page under Inserting Functions



DATEFIRST_INTHISWEEK

Returns the date of the first day of a week.

Public Function DATEFIRST_INTHISWEEK( _ 
Optional ByVal dtDateValue As Date) As Long

    Application.Volatile
    
    DATEFIRST_INTHISWEEK = dtDateValue - VBA.Weekday(dtDateValue, vbUseSystemDayOfWeek) + 1
End Function

DATEFIRST_INTHISMONTH

Returns the date of the first day of a month.

Public Function DATEFIRST_INTHISMONTH( _ 
Optional ByVal dtDateValue As Date) As Long

    Application.Volatile
    If VBA.IsMissing(dtDateValue) Then
        dtDateValue = VBA.Date
    End If

    DATEFIRST_INTHISMONTH = VBA.DateSerial(VBA.Year(dtDateValue), VBA.Month(dtDateValue), 1)
End Function

DATEFIRST_INTHISYEAR

Returns the date of the first day of a year.

Public Function DATEFIRST_INTHISYEAR( _ 
Optional ByVal dtDateValue As Date) As Long

    Application.Volatile
    
    If VBA.IsMissing(dtDateValue) Then
        dtDateValue = VBA.Date
    End If
    
    DATEFIRST_INTHISYEAR = VBA.DateSerial(VBA.Year(dtDateValue), 1, 1)
End Function


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext