+ Reply to Thread
Results 1 to 16 of 16

Convert Text :> Time... Using VBA

Hybrid View

  1. #1
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Convert Text :> Time... Using VBA

    You could try this UDF.
    Function GetTimeFromString(strTime As String) As Date
    Dim dicTimeParts As Object
    Dim arrTimeParts As Variant
    Dim idx As Long
    
        Set dicTimeParts = CreateObject("Scripting.Dictionary")
        
        dicTimeParts("h") = 0
        dicTimeParts("m") = 0
        dicTimeParts("s") = 0
        
        arrTimeParts = Split(strTime, " ")
        
        For idx = LBound(arrTimeParts) To UBound(arrTimeParts)
            dicTimeParts(Right(arrTimeParts(idx), 1)) = Left(arrTimeParts(idx), Len(arrTimeParts(idx)) - 1)
        Next idx
        
        GetTimeFromString = TimeSerial(dicTimeParts("h"), dicTimeParts("m"), dicTimeParts("s"))
            
    End Function
    Last edited by Norie; 04-06-2021 at 12:13 PM.
    If posting code please use code tags, see here.

  2. #2
    Registered User
    Join Date
    02-05-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    365
    Posts
    87

    Re: Convert Text :> Time... Using VBA

    OK, I'm really grateful for this, but if I'm honest I'm having a little trouble seeing how to use this function... I have a SUB already running to manipulate some other areas of the data... I really want to provide a sample, but its full of private customer data.... can I "call" this function? How do I indicate which columns/rows to run it against?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Convert Text Field with time > 24hours to time
    By Viema in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-29-2020, 07:26 AM
  2. [SOLVED] Convert text time to decimal time
    By HappierThan in forum Excel General
    Replies: 5
    Last Post: 06-13-2020, 12:51 AM
  3. Convert Text Time From A Userform Textbox to A Time Value
    By Jenn68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2019, 09:53 PM
  4. Replies: 15
    Last Post: 08-23-2017, 03:32 PM
  5. Excel convert Text time formatted 10h 58m to time so I can sum together
    By slinka in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-04-2016, 10:17 AM
  6. Time stored as text. How can I convert to data and time?
    By matthewbutterworth in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-07-2013, 10:19 AM
  7. [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