View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
vezerid vezerid is offline
external usenet poster
 
Posts: 751
Default Military Time & Colon

The following VBA event procedure will convert the typed entry into
time. If the user types 1500 the cell will then store and display
15:00:00 (if formatted as hh:mm:ss - you can change it to hh:mm only,
since she only types up to minute precision)
The macro will work only if time is entered in cell A1 and assumes
that only time will be entered there. The If needs modification to
allow, e.g. this to happen for all cells in column A:A.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then '<<--- this test might need to change
for other cells, more info needed.
hr = Int(Target.Value / 100)
mn = Target.Value Mod 100
Application.EnableEvents = False
Target.Value = hr / 24 + mn / 1440
Application.EnableEvents = True
End If
End Sub

To install:
Right click on the sheet tab.
Choose View Code...
Paste the above code to the code window in the VBA IDE.

HTH
Kostis Vezerides

On Apr 9, 9:06 pm, cottage6
wrote:
Hi All,
A user here would like to be able to key military hours, say 1500, and have
the cell format to 15:00. She doesn't want to type the colon. I have the
cell formatted as Time 13:30:55 which works great to show her military time.
Is there a way to do this? TIA and have a good day!