Thread: Time format
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default Time format

Try this event sub (it works in column A):

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 1 Then 'column A
If Right(Target, 1) = "a" Or Right(Target, 1) = "p" Then
hournum = Val(Left(Target, Len(Target) - 1))
If Right(Target, 1) = "p" Then hournum = hournum + 12
Target.Value = TimeSerial(hournum, 0, 0)
Target.NumberFormat = "[$-409]h:mm AM/PM;@"
Else
MsgBox "Enter a or p!"
End If
End If
Application.EnableEvents = True
End Sub

Post if you need help to install it!
Regards,
Stefi


€žart€ť ezt Ă*rta:

Hello all:

I was wondering if I can make that when I enter in a cell 5p it should
automatically format as 5:00 PM and so on. And if I enter 5 without a p or a
then it should note that you must enter a "p" or "a". I know how to do it in
a seperate cell as below. But was wondering if I can enter the formula in the
same cell where I put the number, in the format cell feature or somewhere
else. Any help would be appriciated.

The formula I use is:
=IF(OR(RIGHT(A2,1)="a",RIGHT(A2,1)="p"),IF(RIGHT(A 2,1)="a",CONCATENATE(TEXT(LEFT(A2,1),"#:\0\0"),"
","AM"),CONCATENATE(TEXT(LEFT(A2,1),"#:\0\0"), " ","PM")),"Please enter a or
p").

Thanks,