add time to a time stamp

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi i have used your code below, but i want to add time to the date in Row Q can you help me please?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, Rw As Range

  Set Changed = Intersect(Target, Union(Range("H:H"), Range("H:H")))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each Rw In Changed.Rows
      Cells(Rw.Row, "P").Value = Environ("Username")
      Cells(Rw.Row, "Q").Value = Now
    Next Rw
    Application.EnableEvents = True
  End If
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,

Do you mean that Column Q is already filled with Dates ...

and that you only need to add the current time ...?
 
Upvote 0
Hi again,

You could test following modification :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, Rw As Range


  Set Changed = Intersect(Target, Union(Range("H:H"), Range("H:H")))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each Rw In Changed.Rows
      Cells(Rw.Row, "P").Value = Environ("Username")
      Cells(Rw.Row, "Q").Value = Cells(Rw.Row, "Q").Value + (Now - Date)
    Next Rw
    Application.EnableEvents = True
  End If
End Sub

Hope this will help
 
Upvote 0
Thank you. I shall try this in the morning. Will this now put date and time onto row Q? Thanks for the help :)
 
Upvote 0
Thank you. I shall try this in the morning. Will this now put date and time onto row Q? Thanks for the help :)

No ...

Asked you the question if you already had a date in Column Q ...

This macro is designed to ONLY add the time to the existing date ...
 
Upvote 0
Sorry. I got date in column q but wanted to add time/date combined in column q if possible?
 
Upvote 0
Sorry. I got date in column q but wanted to add time/date combined in column q if possible?

Your macro does include date and time, but the macro doesn't format for Date and time.
Code:
Cells(Rw.Row, "Q").NumberFormat = "m/d/yyyy h:mm"
 
Last edited:
Upvote 0
Thank you i shall try this tomorrow morning. Thanks for your time
 
Upvote 0
As indicated by Spiller ... your macro already creates Date and Time ... with the instruction Now ...:smile:
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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
Back
Top