Time format cells

craigwojo

Active Member
Joined
Jan 7, 2005
Messages
274
Office Version
  1. 365
Platform
  1. Windows
making a cell for time to show (for example 10:23am). But I just want to input 10.23 for faster input on the spreadsheet.

Is this possible?

Using Office 2013
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello,

There is a shortcut to enter current time ...

Ctrl Shift ;

Hope this will help
 
Upvote 0
Thats really cool. But I'll be putting in different times not the current
 
Upvote 0
Lightly tested, but here's an event macro (set for Column P in this example) that changes any entry in the format "?#.##" to military time. So, 10.23 becomes 10:23 and 22.23 becomes 22:23.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
'change target range to suit
If Not Intersect(Target, Columns("P")) Is Nothing Then
    For Each c In Intersect(Target, Columns("P"))
        If IsNumeric(c.Value) And c.Value Like "?#.##" Then
            Application.EnableEvents = False
            c.Value = Int(c.Value) & ":" & Right(c.Value, 2)
            Application.EnableEvents = True
        End If
    Next c
End If
End Sub
 
Upvote 0
depends on the source: text or number

time text to time value:
Code:
TimeStr = CStr(ActiveCell.Value)
hrs = Left(TimeStr, InStr(1, TimeStr, ".") - 1)
mins = Mid(TimeStr, InStr(1, TimeStr, ".") + 1, 2)
TimeVal = hrs / 24 + mins / 24 / 60
ActiveCell.NumberFormat = "h:mm;@"
ActiveCell.Value = TimeVal
time number to time value:
Code:
TimeVal_0 = ActiveCell.Value
hrs = Int(TimeVal_0)
mins = (TimeVal_0 - Int(TimeVal_0)) * 100
TimeVal = hrs / 24 + mins / 24 / 60
.
 
Upvote 0
If you have 10.23 in cell A2 ...

you can have the time conversion in cell B2

Code:
=(INT(A2)/24)+((A2-INT(A2))*100)/1440

Hope this will help
 
Upvote 0
Hi again,

Should you need an Event macro ...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
' Adapt Column Input to your situation '
If Target.Column <> 1 Then Exit Sub
If Target = "" Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
  With Target
    .Offset(0, Range("IV2").End(xlToLeft).Offset(0, 1).Row).Value2 = _
    (Int(.Value2) / 24) + ((.Value2 - Int(.Value2)) * 100) / 1440
    .Value2 = .Offset(0, Range("IV2").End(xlToLeft).Offset(0, 1).Row).Value2
    .NumberFormat = "hh:mm"
    .Offset(0, Range("IV2").End(xlToLeft).Offset(0, 1).Row).Clear
  End With
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Hope this will help
 
Upvote 0
@craigwojo

Should you ever visit again the Forum ... sincerely eager to know the final outcome ... :smile:

Thanks a lot ...
 
Upvote 0
I apologize that I didn't get back. But everything worked out correctly. Thank you.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top