Results 1 to 9 of 9

VBA Convert Time from weird format

Threaded View

  1. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: VBA Convert Time from weird format

    Looked again and, yes, you are/were right ... I missed the 0 hours part out.

    I've changed the code now. Both functions work well but my version rounds the milliseconds as you suggested you would like originally. Not a lot in it

    See the attached workbook.

    Option Explicit
    
    Function fCnvTime(ByRef cell As Range)
    
    ' example VBA call: MsgBox fCnvTime(Range("A3"))
    ' example WS call:  =fcnvtime(A3)
    
    Dim vArray
    Dim lMin As Long, lSec As Long, lMS As Long, i As Long
    Dim sTime As String
    
    On Error Resume Next
    
    If Right(cell, 1) = Chr(160) Then cell = Left(cell, Len(cell) - 1)
    vArray = Split(Trim(cell.Value))
    lMin = 0: lSec = 0: lMS = 0
    
    For i = LBound(vArray) To UBound(vArray)
        If LCase(Right(vArray(i), 2)) = LCase("Mn") Then
            lMin = lMin + --Left(vArray(i), Len(vArray(i)) - Len("Ms"))
            GoTo lblNext
        End If
        If LCase(Right(vArray(i), 2)) = LCase("ms") Then
            lMS = lMS + --Left(vArray(i), Len(vArray(i)) - Len("ms"))
            lSec = lSec + Round(lMS / 1000, 0)
            GoTo lblNext
        End If
        If LCase(Right(vArray(i), 1)) = LCase("s") Then
            lSec = lSec + --Left(vArray(i), Len(vArray(i)) - Len("s"))
            GoTo lblNext
        End If
    lblNext:
    Next 'i
    
    fCnvTime = TimeSerial(0, lMin, lSec)
    
    On Error GoTo 0
    
    End Function
    
    Sub test()
    
    MsgBox fCnvTime(Range("A10"))
    
    End Sub

    Regards, TMS
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Getting rid of weird time format 01m 16s
    By rooonik in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-29-2013, 11:08 AM
  2. Convert date and time in serial number format to text format
    By nda13112 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-11-2013, 02:45 PM
  3. [SOLVED] Time measures in weird format
    By andrewmo in forum Excel General
    Replies: 10
    Last Post: 09-21-2012, 03:41 PM
  4. Excel: How to convert time format into number format that can be added?
    By Frances Jones in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-17-2012, 04:10 PM
  5. [SOLVED] convert time imported as text to time format for calculations
    By batfish in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-27-2005, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1