VBA Function: DateSerial
The VBA function DateSerial returns a date based on a year, month, and day.
Usage:
DateSerial(year, month, day)
Example of Usage
Creating a date using the 3 arguments required by the function (year, month, day):
Sub example()
yearDate = 2024
monthDate = 10
dayDate = 30
myDate = DateSerial(yearDate, monthDate, dayDate)
MsgBox myDate 'Returns the date corresponding to 10/30/2024
End Sub
An equivalent alternative using the CDate function:
Sub example()
yearDate = 2024
monthDate = 10
dayDate = 30
myDate = CDate(yearDate & "/" & monthDate & "/" & dayDate)
MsgBox myDate 'Returns the date corresponding to 10/30/2024
End Sub