how can i change time to AM/PM in this code

cardinaldeb

New Member
Joined
Aug 21, 2018
Messages
1
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 12/04/2012
' [URL]http://www.mrexcel.com/forum/excel-questions/672492-scan-barcode-excel-date-time-stamp-out.html[/URL]
If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long
With Application
  .EnableEvents = False
  .ScreenUpdating = False
  lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
  If lc = 1 Then
    Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy h:mm")
  ElseIf lc > 2 Then
    Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy h:mm")
  End If
  .EnableEvents = True
  .ScreenUpdating = True
End With
End Sub
 
Last edited by a moderator:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 12/04/2012
' http://www.mrexcel.com/forum/excel-q...stamp-out.html
If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub

Dim lc As Long

With Application
  .EnableEvents = False
  .ScreenUpdating = False
  lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
  lc = lc + IIf(lc = 1, 2, 1)
  Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy h:mm AMPM")
  .EnableEvents = True
  .ScreenUpdating = True
End With

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

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