how to add current time to an existing (static) date?

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
322
Office Version
  1. 2010
Platform
  1. Windows
my application/code:

Via a userform, the user enters data into several fields, one of which is a text box for a DATE to be entered.

When the user closes the form, the data from the form is posted over to the main worksheet.

here is my code for posting (and formatting) the date field from the form to the worksheet:
Code:
.Cells(10, lCol + 2).Value = Me.txtDateBox.Value
.Cells(10, lCol + 2).NumberFormat = "MM'/'dd'/'yyyy"

So over on the worksheet, in the specific cell listed above, it now looks like this:

14Date.PNG


Also when the data from the userform is moved over to the worksheet, another cell has whatever the current TIME happens to be placed into it (and formatted as shown):

the code for this:
Code:
With Cells(3, lCol + 2)
    .Value = Now()
    .Value = TimeValue(.Value)
    .NumberFormat = "h:mm:ss AM/PM"
End With

So out on the worksheet, and in the specific cell listed above, it looks like this:

15Date.PNG


here's my problem and my request:

I need to have the two cells listed above combined. The result of combining those 2 cells (the DATE cell in -> (10, lCol + 2), and the TIME cell in -> (3, lCol + 2) ) needs to look like the example shown below and placed into: (6, lCol + 1) .

The resulting cell in (6, lCol + 1) after being combined and formatted correctly needs to look like THIS:

12Date.PNG


Thank you in advance for the solution, or suggestions. :)
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,682
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
= CDate(Me.txtDateBox.Value) + TimeValue(Now)
 
Solution

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
322
Office Version
  1. 2010
Platform
  1. Windows
Nailed it. (y) (first try too! 🍻)

Thank you, Fluff.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,682
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,861
Messages
5,627,314
Members
416,239
Latest member
Counselor85027

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top