Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Add colon to time automatically, still recognize it as time

Good morning! I need to type 0125 into a cell and it automatically add the colon (01:25 or 1:25- Either works). I have found several solutions to this BUT I also need Excel to still recognize the cell as "Time" so I can figure elapsed time in another cell. Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 538
Default Add colon to time automatically, still recognize it as time

kellye.smiley wrote:

Good morning! I need to type 0125 into a cell and it automatically add
the colon (01:25 or 1:25- Either works). I have found several solutions
to this BUT I also need Excel to still recognize the cell as "Time" so I
can figure elapsed time in another cell.


I believe this requires VBA. This is what I use:

Sub fixTimes(what As Range)
Dim cell As Range
For Each cell In what
'fixed by Claus Busch
If (InStr(cell.Value, ".") < 1) And (IsNumeric(cell.Formula)) Then
Select Case cell.Formula
Case 0 To 2359
cell.Value = (CLng(cell.Formula) \ 100) & ":" & _
(CLng(cell.Formula) Mod 100)
End Select
End If
Next
End Sub

(Note that this doesn't check for invalid times, like "999".)

I find it convenient to call it in Workbook_SheetChange, like so:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim cell As Range
For Each cell In Target
Select Case cell.Column
Case FIRSTTIMECOL To LASTTIMECOL 'globals defined elsewhere
fixTimes cell
End Select
Next
End Sub

--
There's never enough time to do all the nothing you want.
-- Calvin
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
adding a colon to military time Suzanne Excel Worksheet Functions 7 February 7th 13 10:51 AM
Need to add semi colon in time numbers RustyB Excel Discussion (Misc queries) 2 April 30th 10 12:49 AM
Editing time that has its colon removed rhhince[_2_] Excel Worksheet Functions 1 January 10th 10 03:22 AM
Military Time & Colon cottage6 Excel Worksheet Functions 3 April 9th 08 09:50 PM
How can Excel do daily timesheet, -lunch time, & not use colon in. Jan Excel Worksheet Functions 2 March 8th 05 10:05 PM


All times are GMT +1. The time now is 02:35 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"