Combine Date and Time Columns in Microsoft Excel with VBA
Question details
Combine dates from column E and times from column G into column H, display the results as MM/DD/YYYY HH:MM, replace formulas with values, and copy those values back to column E.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Each row contains a date and a separate time that must become one numeric date-time value.
- Observed behavior
- The desired result is a combined date-time value in column E, with column H used as an intermediate output column.
Confirm that columns E and G contain actual Excel date and time values, not text, and that column H is available for output. The macro assumes headers in row 1 and data beginning in row 2; it overwrites the existing dates in column E.
Use VBA to combine the date and time and copy the values back
Use this macro to complete the calculation, formatting, formula-to-value conversion, and copy-back operation in one run.
Excel stores dates as serial numbers and times as fractions of a day. Adding a date-only value to a time-only value produces a numeric date-time value; number formatting controls how that value appears.
This macro assumes every data row has a valid date in column E and a valid time in column G. Check for blanks, errors, or existing time components in column E before running it.
In desktop Excel, open the workbook and choose Developer > Visual Basic. If the Developer tab is hidden, enable it in Excel's ribbon settings.
In the VBA editor, select your workbook in Project Explorer, choose Insert > Module, and paste this code: Sub CombineDateAndTime() Dim ws As Worksheet Dim lastRow As Long Dim outputRange As Range Set ws = ThisWorkbook.Worksheets("Sheet1") lastRow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row If lastRow < 2 Then Exit Sub Set outputRange = ws.Range("H2:H" & lastRow) With outputRange .FormulaR1C1 = "=RC[-3]+RC[-1]" .Calculate .Value = .Value .NumberFormat = "mm/dd/yyyy hh:mm" End With With ws.Range("E2:E" & lastRow) .Value = outputRange.Value .NumberFormat = "mm/dd/yyyy hh:mm" End With End Sub
Replace "Sheet1" with the exact worksheet tab name. If your data does not start in row 2, adjust the starting row in both range definitions and the lastRow check. Return to Excel, choose Developer > Macros, select CombineDateAndTime, and click Run.
Select a populated cell in column H and check that the formula bar no longer contains an =E2+G2 formula. Check the corresponding cell in column E to confirm that it contains the same date and time, displayed as MM/DD/YYYY HH:MM.
Combine the columns with a formula and Paste Special
Use this method when you need the same result without running VBA.
Combine Date and Time Values in WPS Spreadsheets
WPS Spreadsheets can complete this task with a formula, custom number formatting, and Paste Special. Add columns E and G in column H, convert the results to values, and paste them back into column E without relying on VBA.
- 1. Open the spreadsheet and enter the formula: Open your workbook in WPS Spreadsheets. In H2, enter =E2+G2, then drag the fill handle down to the last data row.
- 2. Format the combined results: Select the populated range in column H, right-click, and choose Format Cells. Under Custom, enter mm/dd/yyyy hh:mm and confirm.
- 3. Convert the formulas to values: Copy the populated range in column H, right-click the same selection, and choose Paste Special > Values.
- 4. Replace the dates in column E: Copy the converted range in column H, select E2, and use Paste Special > Values. Apply the same custom date-time format to the destination range in column E.

Frequently Asked Questions
Why does adding the date and time show a decimal number?
The result is Excel's underlying date-time serial number. Select the result cells, open Format Cells > Custom, and enter mm/dd/yyyy hh:mm to display the number as a date and time.
Will the combined result remain usable for sorting and calculations?
Yes. The formula =E2+G2 produces a numeric value, and Paste Special > Values preserves that numeric result. Avoid using TEXT(E2+G2,"mm/dd/yyyy hh:mm") if you need numeric date-time values, because TEXT returns a text string.
What should I check if the formula returns #VALUE!?
Check whether the source cells contain text rather than numeric dates and times. Enter =ISNUMBER(E2) and =ISNUMBER(G2) in unused cells; both should return TRUE. Convert text entries to actual date or time values before running the macro or filling down the formula.
Can I run the macro again after it has copied the results to column E?
Not safely with unchanged inputs. Column E already contains the time after the first run, so running the macro again would add the time from column G a second time. Run it only when column E contains date-only values, or restore the original date-only inputs first.
Does hh:mm use minutes or months for the second part?
In the custom format mm/dd/yyyy hh:mm, Excel interprets the mm immediately after hh: as minutes. The first mm represents the month, and hh:mm displays the time using a 24-hour clock without seconds.




