Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 108
Default Military Time & Colon

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!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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!


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 108
Default Military Time & Colon

Awesome! I'm not sure what cells the user would need to format this way, but
I'll assume many entries in several columns. She has a Start Shift, End
Shift, Start Lunch and End Lunch she would like to be able to do this in, so
that's 4 columns. Below is your modified code with range c3:c20 which works
fine. How could I change this to include extra columns? I tried changing
this a bit but it didn't work.


Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("c3:c20")) Is Nothing Then
Exit Sub
End If
If Target.Cells.Count 1 Then
Exit Sub
End If
If Target.Value = "" Then
Exit Sub
End If
With Target

hr = Int(Target.Value / 100)
mn = Target.Value Mod 100
Application.EnableEvents = False
Target.Value = hr / 24 + mn / 1440
Application.EnableEvents = True

End With
End Sub
"vezerid" wrote:

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!



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Military Time & Colon

If Application.Intersect(Target, Range("C:F")) for contiguous full columns

If Application.Intersect(Target, Range("C3:C30, F5:F56, G3:K20")) for

non-contiguous ranges


Gord Dibben MS Excel MVP


On Wed, 9 Apr 2008 12:51:00 -0700, cottage6
wrote:

Awesome! I'm not sure what cells the user would need to format this way, but
I'll assume many entries in several columns. She has a Start Shift, End
Shift, Start Lunch and End Lunch she would like to be able to do this in, so
that's 4 columns. Below is your modified code with range c3:c20 which works
fine. How could I change this to include extra columns? I tried changing
this a bit but it didn't work.


Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("c3:c20")) Is Nothing Then
Exit Sub
End If
If Target.Cells.Count 1 Then
Exit Sub
End If
If Target.Value = "" Then
Exit Sub
End If
With Target

hr = Int(Target.Value / 100)
mn = Target.Value Mod 100
Application.EnableEvents = False
Target.Value = hr / 24 + mn / 1440
Application.EnableEvents = True

End With
End Sub
"vezerid" wrote:

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!




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Standard Time to Military Time in Excel mtvschultz Excel Discussion (Misc queries) 3 May 5th 23 11:42 AM
adding a colon to military time Suzanne Excel Worksheet Functions 7 February 7th 13 10:51 AM
formula for converting military time to standard time, etc Pattio Excel Discussion (Misc queries) 8 February 17th 08 01:12 AM
Converting Standard Time into Military Time mtvschultz Excel Discussion (Misc queries) 3 February 15th 08 07:34 PM
Show timesheet time in and out in regular time versus military tim John Excel Worksheet Functions 1 November 11th 05 05:14 AM


All times are GMT +1. The time now is 11:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"