Combine day, month and year to create date
This tutorial shows how to combine the day, month and year values that are separately captured to derive with a date through the use of an Excel formula, with the DATE function or VBA
Hard coded formula
Cell reference formula
=DATE(2019,3,17)
=DATE(D5,C5,B5)
|
GENERIC FORMULA
=DATE(year,month,day)
ARGUMENTS GENERIC FORMULA
=DATE(year,month,day)
ARGUMENTS EXPLANATION This formula uses the DATE function to combine the day, month and year values to derive with a date.
Click on either the Hard Coded or Cell Reference button to view the formula that either has the day, month and year numbers entered directly in the formula or referenced to cells.
In this example we are combining day 17 with the third month and year 2019 to derive with a date. |
Hard coded against single cell
Sub Combine_day_month_and_year()
'declare variables
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'combine day, month and year to create with a date
ws.Range("B5") = DateSerial(2019, 3, 17)
ws.Range("B5") = DateSerial(2019, 3, 17)
End Sub
Cell reference against single cell
Sub Combine_day_month_and_year()
'declare variables
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'combine day, month and year to create with a date
ws.Range("E5") = DateSerial(ws.Range("D5"), ws.Range("C5"), ws.Range("B5"))
ws.Range("E5") = DateSerial(ws.Range("D5"), ws.Range("C5"), ws.Range("B5"))
End Sub
Hard coded against range of cells
Sub Combine_day_month_and_year()
'declare variables
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'combine day, month and year to create with a date
For x = 5 To 8
ws.Range("B" & x) = DateSerial(2019, 3, 17)
Next x
End Sub
Cell reference against range of cells
Sub Combine_day_month_and_year()
'declare variables
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'combine day, month and year to create with a date
For x = 5 To 8
ws.Range("E" & x) = DateSerial(ws.Range("D" & x), ws.Range("C" & x), ws.Range("B" & x))
Next x
End Sub
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Combine date and time | How to combine a date and time in one cell through the use of an Excel formula or VBA | |
Difference in months between two dates | How to find the difference in months between two dates through the use of an Excel formula or VBA | |
Return last day of a current month | How to return the last day of a current month through the use of an Excel formula or VBA |
RELATED FUNCTIONS
Related Functions | Description | Related Functions and Description |
---|---|---|
DATE Function | The Excel DATE function returns a date through the use of individual year, month and day parameters |