Time Format

  • Thread starter Thread starter MAX
  • Start date Start date
M

MAX

Hello

I have a worksheet where one of the columns is TIME. All I want is that I
write 0315 (3.15 AM) and it appears as 03:15. Is there a solution for this?

Thanks in advance.
 
You need an event macro for that:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 10 Then 'change column No as necessary
Application.EnableEvents = False
ora = Int(Target.Value / 100)
perc = Target.Value - ora * 100
Target.Value = TimeSerial(ora, perc, 0)
Application.EnableEvents = True
End If
End Sub

This one works for column J (column 10).
Post if you need help to install it!

--
Regards!
Stefi



„MAX†ezt írta:
 
Try the below..Modify the range to suit your requirement

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing Then
If IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target = Left(Format(Target.Value, "0000"), 2) & ":" &
Right(Format(Target.Value, "0000"), 2)
Application.EnableEvents = True
End If
End If
End Sub
 
An error is given and to help you these 2 lines appear in RED.
Target = Left(Format(Target.Value, "0000"), 2) & ":" &
Right(Format(Target.Value, "0000"), 2)
 
That should be in one line..Try copy pasting the below code....

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A10")) Is Nothing Then
If IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target = Left(Format(Target.Value, "0000"), 2) & ":" & _
Right(Format(Target.Value, "0000"), 2)
Application.EnableEvents = True
End If
End If
End Sub
 
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A7:A68")) Is Nothing Then
Application.EnableEvents = False
ora = Int(Target.Value / 100)
perc = Target.Value - ora * 100
Target.Value = TimeSerial(ora, perc, 0)
Application.EnableEvents = True
End If
End Sub

--
Regards!
Stefi



„MAX†ezt írta:
 
Back
Top