Join a Date and Time into a Single Cell using VBA Macros in Excel

Add to Favorites

In order to combine a cell that has a date with a cell that has a time, using a Macro and VBA in Excel, you must sum the data.

For instance, if you have one cell formatted as a date and another cell formatted as a time and you want to combine them into a single cell with the date and time together, you cannot simply concatenate the data.

If the date is in cell A1 and the time in cell B1 and you want to combine them in cell C1, you must do something like this:

Sub CombineDateTime()

Range("C1").Value = Range("A1").Value + Range("B1").Value

End Sub

Notice the plus sign in between the Range for A1 and B1.

It is easy to think that you should simply concatenate these two values and then put that into a cell but this will not work. Remember that dates and times are stored as numbers in Excel.  This is why you need to sum or add these date and time values in order to get the correct result.

Also, in case Excel does not automatically format the destination cell as you would like, remember to ensure that the correct date/time formatting is being used, whichever you want, as this can dramatically change the visible output of a cell containing a date and time value.

I hope this was helpful!  Remember to share this tutorial and follow us on Google Plus! Smile


Downloadable Files: Excel File

Question? Ask it in our Excel Forum

Our Excel Courses

  • Skill Level: All Levels
  • |
  • 5 hours+

How to make a fully featured professional form in Excel that is unbreakable. This includes how to use the form to store, view, edit, and delete data from a data storage worksheet.

  • Skill Level: All Levels
  • |
  • 2 hours

Send Emails from Excel using VBA and Macros. This course starts from the Basics and builds up to more advanced examples with attaching workbooks, worksheets, PDF's, automatically sending emails, including a signature, error handling, increasing speed, and more.

Similar Content on TeachExcel
Excel Data Validation - Limit What a User Can Enter into a Cell
Tutorial: Data Validation is a tool in Excel that you can use to limit what a user can enter into a...
How to Use Multiple Functions and Formulas in a Single Cell in Excel
Tutorial: Lets learn how to put multiple functions and formulas in a single cell in Excel in order t...
Use Macros with UserForms
Tutorial: This tutorial explains how macros interact with UserForms. This includes an explanation of...
Show a Single Comment in Excel - Means the Comment is Always Visible, No Hovering Necessary
Macro: This macro in Excel allows you to display or show a particular comment in Excel. This will...
Add a Drop Down Menu to a Cell in Excel - Data Validation Macro
Macro: Add a drop down menu or list to a cell in Excel with this free Excel macro. This is a grea...
Increment a Date By X Days for Each Row in Excel
Tutorial: How to quickly increment a date by a certain number of days for each entry. Type the first...