View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default please help.is it possible re-edit macro to convert text like 1530-2200 to time format automatically? i got macro which works with 4 digits like 1234 to 12:34 ,but i don't know how to make it work for 4 digits dash and 4 digits?

Hi Michael,

Am Wed, 22 Jan 2014 05:29:30 -0800 (PST) schrieb :

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim TimeStr As String


try:

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("A1:A10")) Is Nothing _
Or Target.Count 1 Then Exit Sub

Dim myTime As Double

Application.EnableEvents = False
Select Case Len(Target)
Case 1, 2
myTime = Target / 1440
Case 3
myTime = Left(Target, 1) / 24 + Right(Target, 2) / 1440
Case 4
myTime = Left(Target, 2) / 24 + Right(Target, 2) / 1440
Case 5
myTime = Left(Target, 1) / 24 + Mid(Target, 2, 2) / 1440 + _
Right(Target, 2) / 86400
Case 6
myTime = Left(Target, 2) / 24 + Mid(Target, 3, 2) / 1440 + _
Right(Target, 2) / 86400
Case Is 6
myTime = 0
End Select
If myTime 0 Then
Target = myTime
Target.NumberFormat = "h:mm:ss"
Else
Target.Clear
Target.NumberFormat = "General"
MsgBox "You did not enter a valid time"
End If
Application.EnableEvents = True
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2