Solved

# Is there a way to enter military time in a cell (1700), and have the result formatted in hh:mm (5:00 PM)?

Posted on 2016-08-29
49 Views
Is there a way to enter military time in a cell (for ex, 1700), and have the result formatted in hh:mm (for ex, 5:00 PM)?

Thanks!
0
Question by:Cactus1994
• 5
• 4
• 2

LVL 21

Expert Comment

By default if you set the cell or column to format as Time 5:00 PM and enter 17:00 in the cell you will see it as 5:00 PM

Is that what you are looking for or are you looking for 1700 to be converted to Standard US TIME?
0

Author Comment

What I'm really trying to do is just enter regular time without the colon, for a large Excel sheet for payroll every week.

I thought using military time would work, as it at saved a couple steps entering 17:00 and then having the cell formatted so the result after typing it into the cell was 5:00 PM. (I obviously just using the "1:30 PM" format for the cells.)

Is there an easier way so I can just enter time without using the : (colon)?  It's a pain entering dozens and dozens of clock-in and clock-out times, and always having to shift and click to enter a colon into every time I input. Thanks.
0

LVL 43

Expert Comment

Can you use a helper column?
0

LVL 21

Expert Comment

you can do something like this.
Format the column to Time 5:00 PM and enter this formula in
``````=TIMEVALUE((CONCAT(LEFT(F1,2),":",MID(F1,3,2))))
``````

F1 is where you enter you 1700 and G1 is where there formula is entered.
0

LVL 43

Expert Comment

Or, you can use an event handler macro like this. This works for column 3. You can change this in the second row

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then
If Len(Target) = 4 And IsNumeric(Target) Then
Target.Value = Left(Target, 2) & ":" & Right(Target, 2)
End If
End If
End Sub
0

Author Comment

Unfortunately, I can't use a helper cell....
0

Author Comment

Saqib ... I'm a novice at macros and VBA. How exactly do I enter in what you suggested so this will work for me?
0

Author Comment

I am entering times into cells A7:O34 in one particular tab of a large Excel workbook.
0

LVL 43

Expert Comment

Right-click on the sheet tab name
Select View code
Paste the given code in the VBA window
Close the VBA window
0

LVL 43

Accepted Solution

Saqib Husain, Syed earned 500 total points
For the specified range

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A7:O34")) Is Nothing Then
If Len(Target) = 4 And IsNumeric(Target) Then
Target.Value = Left(Target, 2) & ":" & Right(Target, 2)
End If
End If
End Sub
0

Author Closing Comment

Got it. Perfect! It works ... thank you very much!!
0

## Featured Post

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…